3

我有一个 Windows 应用商店应用程序(C# + XAML)并想为它创建一些单元测试。我在我的解决方案中为此创建了单元测试项目,默认测试方法工作正常。然后我将我的项目添加为对单元测试项目的引用,并且测试停止工作:

------ Discover test started ------
========== Discover test finished: 1 found (0:00:00,8748072) ==========
------ Run test started ------
Updating the layout...

Copying files: Total 2 mb to layout...

Registering the application to run from layout...

Deployment complete. Full package name: "58d19822-a649-46ba-b3fd-36c60b2709d7_1.0.0.0_neutral__t4zwj4xd20b1w"

Failed to activate Windows Store app unit test executor. Error: The remote procedure call failed.
========== Run test finished: 0 run (0:00:05,0596667) ==========

我用谷歌搜索了很多,发现一个解释错误的线程可能在 App.xaml 中,实际上我可以将它追踪到这个 TextBlock:

<TextBlock Grid.ColumnSpan="2" controls:HighLightString.FullText="{Binding Path=FullName}" controls:HighLightString.SelectedText="{Binding DataContext.QueryText, ElementName=resultsPanel}" controls:HighLightString.FgColor="{StaticResource SAPHighlightColor}"  Style="{StaticResource TileTitleTextStyle}" Margin="20,0,0,0" TextTrimming="WordEllipsis"/>

如果我将其更改为:

<TextBlock Grid.ColumnSpan="2" Text="{Binding Path=FullName}" Style="{StaticResource TileTitleTextStyle}" Margin="20,0,0,0" TextTrimming="WordEllipsis"/>

测试运行良好,但该文本块上不再有搜索突出显示。

我怎样才能同时拥有 - 搜索突出显示和在我的解决方案中运行单元测试?

4

3 回答 3

5

这可能与https://connect.microsoft.com/VisualStudio/feedback/details/790477/winrt-mstest-runner-fails-when-using-ilist-t-properties-of-custom-types-from-xaml有关

据我所知,在 Xaml 中使用某些自定义类型与 WinRT 单元测试运行程序不兼容,因为在某些情况下它不提供正确的IXamlType接口实现。

因此,您使用的这些可附加属性可能会导致测试运行程序为它们提供不正确的元数据。(无法看到您的HighLightString类,很难确定。但您可以通过为您的单元测试项目打开混合模式调试并调试测试来验证是否是这种情况。配置 Visual Studio 以在以下情况下中断所有 CLR 异常抛出(不仅仅是在未处理时),如果你最终NotImplementedException在一个被调用的类型中遇到了一个(可能是在其他一些异常之后),RunTimeXamlSystemBaseType那么这就是你遇到的问题。)

过去我通过避免将相关类型放入我的App.xaml. 如果您尝试加载相关的 Xaml,您只会遇到此问题。(当然,如果您确实需要将这些东西放在全球范围内,那么帮助不大。)

于 2013-06-19T14:10:12.197 回答
0

在此处的 Microsoft Connect 站点上对此有一个错误:https ://connect.microsoft.com/VisualStudio/feedback/details/848688/unit-testing-windows-store-app-fails-when-style-contains-custom -附加依赖属性

列出的解决方法是引用应用程序的构建 .exe,而不是使用项目引用。我可以确认该解决方法确实有效。

于 2015-01-09T16:34:50.663 回答
0

我有完全相同的问题。我在列表框的 DataTemplate 中使用了适用于 Windows 8.1 的 Microsft PrismAdventure Works Shopping Example
的 HighlightOnErrors 行为。

<interactivity:Interaction.Behaviors>
                <behaviors:HighlightOnErrors PropertyErrors="{Binding Errors[Value], Mode=TwoWay}" 
                                                         OriginalStyleName="VariationTableItemTextBoxStyle" 
                                                         HighlightStyleName="HighlightVariationTableItemTextBoxStyle"/>
            </interactivity:Interaction.Behaviors>

该行为工作正常,单元测试运行良好,但在 Listbox Item 模板中没有这种行为。

于 2014-01-07T11:13:14.220 回答