WP7:UnitTest Framework入门:XamlParseException

时间:2011-10-24 21:58:54

标签: unit-testing windows-phone-7

我想在我的WP7项目中添加单元测试。我按照http://smartypantscoding.com/a-cheat-sheet-for-unit-testing-silverlight-apps-on-windows-phone-7上的tutrials开始进行单元测试。但我无法让它运行起来。

我按照教程中的所有步骤创建了基本测试。

但是只要我想启动项目,Visual Studio就会抛出一个错误:

发生XamlParseException 无法使用Name / Key typeNameConverter找到资源[Line:47 Position:24]

第47行引用了初始的CreateTestPage:

private void MainPage_Loaded(object sender, RoutedEventArgs e)
{ 
            SystemTray.IsVisible = false; 
Line47:     var testPage = UnitTestSystem.CreateTestPage() as IMobileTestPage; 
            BackKeyPress += (x, xe) => xe.Cancel = testPage.NavigateBack(); 
            (Application.Current.RootVisual as PhoneApplicationFrame).Content = testPage; 
} 

希望你能帮助我! 谢谢!

5 个答案:

答案 0 :(得分:4)

您可能正在使用Jeff Willcox的Windows Phone 7工具包。如果您想在新的Windows Phone下运行它,请尝试使用新版本的工具包。 尝试使用Jeff Willcox的Windows Phone 7.5工具包(芒果)在此处获取:http://www.jeff.wilcox.name/2011/06/updated-ut-mango-bits/ 祝你好运。

答案 1 :(得分:4)

昨天我遇到了这个问题,发现App.xaml配置错误。使用guesswork(即什么接口实现IValueConverter?),我找到了这个解决方案,它看起来效果很好。

首先,将此命名空间添加到<Application>命名空间:

xmlns:Client="clr-namespace:Microsoft.Silverlight.Testing.Client;assembly=Microsoft.Silverlight.Testing">

然后将其添加到<Application>

<Application.Resources>
  <Client:TypeNameVisibilityConverter x:Name="typeNameConverter" />
  <Client:FontWeightConverter x:Name="fontWeightConverter" />
</Application.Resources>

我希望这对某人有用。

我可以确认Michael Dumont的解决方案也能正常工作,但是当你因为某种原因没有连接调试器时,你无法查看试图查看损坏测试信息的测试运行细节。

答案 2 :(得分:2)

确保您的单元测试项目适用于.Net Framework 3.0或3.5,并使用Jeff Wilcox创建的Unit Test Framework Assemblies compatible with Mango。当项目用于.Net Framework 4.0时,我遇到了同样的错误。

答案 3 :(得分:1)

我也收到了这个错误,并且找到了它正在寻找的ValueConverters,并且能够成功地使框架正常工作。

的App.xaml

<!--Application Resources-->
<Application.Resources>
    <s:typeNameConverter x:Name="typeNameConverter"></s:typeNameConverter>
    <s:fontWeightConverter x:Name="fontWeightConverter"></s:fontWeightConverter>
</Application.Resources>

值转换器

public class typeNameConverter : IValueConverter {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
        throw new NotImplementedException();
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
        throw new NotImplementedException();
    }
}

public class fontWeightConverter : IValueConverter {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
        throw new NotImplementedException();
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
        throw new NotImplementedException();
    }
}

答案 4 :(得分:0)

异常是指TestPage中的XAML。所以你发布了错误的代码。

无论如何,错误很明显。您的XAML中声明的typeNameConverter丢失了。很可能你忘了添加对声明它的程序集的引用,或者更新xmlns使它指向不同的程序集,而不仅仅是一个不同的命名空间。

相关问题