繁体   English   中英

使用 Xunit 运行单元测试

[英]Running unit test using Xunit

我在 UWP 项目中添加了一个单元测试 class 并将以下引用添加到我的主要 class 库中。

参考

当我添加一个新的 class 库并在那里添加我的测试类时,class 库上的测试方法会执行,但主项目上的测试方法会引发以下异常。

System.InvalidOperationException: The following test container was not found: 'F:\test\WinApp\bin\x64\Debug\WinApp.exe'. This can be resolved by one or more of the following steps:
1. The test container does not exist on disk and the corresponding project might need to be built successfully.
2. For .NET Core based test projects, please ensure that a nuget package reference to "Microsoft.NET.Test.SDK" exists and that it uses the latest stable version.
3. For .NET based test projects, the project might be marked as a non-test project through an msbuild property, "IsTestProject". Please consider clearing it or set "<IsTestProject>true</IsTestProject>" in a "<PropertyGroup>" in the test project.
   at Microsoft.VisualStudio.TestWindow.Client.TestContainer.TestContainerProvider.<GetTestContainerAsync>d__42.MoveNext()

我尝试了上述方法,但没有用。

我想在我的主 class 库中编写我的测试类,该库可执行任何建议。我正在尝试这样做,因为我无法从测试项目中添加对主 class 库的引用并运行它。如果我尝试这样做,则会引发以下错误。

在此处输入图像描述 我的测试项目是一个单元测试应用程序(通用 Windows)

在此处输入图像描述

我没有在构建服务器中运行

由于项目有 2 个Default.rd.xml文件可用,因此发生冲突。

运行时指令 (.rd.xml) 文件是 XML 配置文件,它指定指定的程序元素是否可用于反射。 (参考: Microsoft 的运行时指令文档

因此,如果您的单元测试项目没有使用反射,那么从测试项目(F:\test\UnitTestProject2\Properties 中的那个)中删除 Default.rd.xml 文件应该是安全的。

做一个完整的重建,你应该对 go 很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM