[英]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 庫的引用並運行它。如果我嘗試這樣做,則會引發以下錯誤。
我沒有在構建服務器中運行
由於項目有 2 個Default.rd.xml
文件可用,因此發生沖突。
運行時指令 (.rd.xml) 文件是 XML 配置文件,它指定指定的程序元素是否可用於反射。 (參考: Microsoft 的運行時指令文檔
因此,如果您的單元測試項目沒有使用反射,那么從測試項目(F:\test\UnitTestProject2\Properties 中的那個)中刪除 Default.rd.xml 文件應該是安全的。
做一個完整的重建,你應該對 go 很好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.