WP7: 使用UnitTest框架入门:XamlParseException

4
我想为我的WP7项目添加单元测试。我按照http://smartypantscoding.com/a-cheat-sheet-for-unit-testing-silverlight-apps-on-windows-phone-7上的教程开始了单元测试。但是我无法让它运行。
我按照教程中的所有步骤并创建了基本测试。但是一旦我想要启动项目,Visual Studio就会报错: XamlParseException异常发生 找不到名称/关键字typeNameConverter的资源[行:47 位置: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个回答

4
昨天我遇到了这个问题,发现App.xaml的配置不正确。通过猜测(即哪些接口实现了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的解决方案也能够运行,但是当你在没有调试器的情况下尝试查看损坏测试的信息时,无法查看测试运行的详细信息很令人烦恼。

4

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


2

确保您的单元测试项目是针对 .Net Framework 3.0 或 3.5,并使用 Jeff Wilcox 创建的与 Mango 兼容的单元测试框架程序集。如果项目针对 .Net Framework 4.0,则会出现相同的错误。


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();
    }
}

0

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

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接