gpt4 book ai didi

c# - 使用自定义控件时 Windows 应用商店应用程序单元测试失败

转载 作者:可可西里 更新时间:2023-11-01 14:50:45 24 4
gpt4 key购买 nike

我有一个 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"/>

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

如何在我的解决方案中同时拥有搜索亮点和运行单元测试?

最佳答案

这可能与 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 interface某些情况下的实现。

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

我过去通过避免将相关类型放入我的 App.xaml 来解决这个问题。如果您尝试加载相关的 Xaml,您只会遇到这个问题。 (当然,如果你真的需要这些东西在全局范围内,那就没什么帮助了。)

关于c# - 使用自定义控件时 Windows 应用商店应用程序单元测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16539794/

24 4 0
文章推荐: hadoop - 如何使用 hdfs shell 命令检查文件是否存在
文章推荐: html+css tables - tr 的 border-bottom 与 td/th 的 border-right 重叠
文章推荐: hadoop - 将普通的java程序转换为map reduce
文章推荐: html - 中 SVG 的链接 "out"