【发布时间】:2018-07-31 18:37:23
【问题描述】:
我继承了为解决方案创建构建的乐趣,该解决方案在应用程序项目中而不是在测试项目中具有测试文件。
MySolution
|__MyProject
|__MyClass.cs
|__MyClassTest.cs
我之前创建的所有版本都有一个测试项目,并且在 VSTS 中的测试任务上运行良好。由于没有测试程序集,因此不会拾取并运行测试。
我在构建步骤中尝试将项目程序集作为“测试程序集”,但这不起作用。我怎样才能做到这一点?
编辑
这里是日志,指向程序集。
2018-07-31T18:31:25.0890193Z Starting test execution, please wait...
2018-07-31T18:31:25.8549638Z NUnit Adapter 3.10.0.21: Test execution started
2018-07-31T18:31:25.8558752Z Running all tests in C:\agent\_work\14\s\MyProject\bin\MyProject.dll
2018-07-31T18:31:26.8625176Z NUnit couldn't find any tests in C:\agent\_work\14\s\MyProject\bin\MyProject.dll
2018-07-31T18:31:26.9532542Z Running all tests in C:\agent\_work\14\s\MyProject\obj\Release\Before-PostSharp\MyProject.dll
2018-07-31T18:31:26.9539232Z NUnit couldn't find any tests in C:\agent\_work\14\s\MyProject\obj\Release\Before-PostSharp\MyProject.dll
2018-07-31T18:31:26.9691860Z Running all tests in C:\agent\_work\14\s\MyProject\obj\Release\MyProject.dll
2018-07-31T18:31:26.9692255Z NUnit couldn't find any tests in C:\agent\_work\14\s\MyProject\obj\Release\MyProject.dll
2018-07-31T18:31:26.9726008Z NUnit Adapter 3.10.0.21: Test execution complete
【问题讨论】:
-
项目是否有适当的测试框架适配器被引用为 NuGet 包? “测试项目”与常规项目相比,没有什么特别之处会阻止测试被发现,除了你在测试发现中遇到的正常类型的问题。
-
@DanielMann 似乎是。我添加了 NUnit3TestAdapter,这是我在有测试项目的构建中遇到 nunit 问题时需要的。
-
正如@DanielMann 所说,这应该可以工作。它在 Visual Studio 中有效吗?你确定你的过滤器没有排除这个程序集吗?
-
好的,事实上这很好,在 VS 中更容易修复它:-) 我只是尝试在 VS 中设置一个命令行应用程序,添加一个测试类,+ nunit 和适配器,它工作直接地。现在设置相同的 VSTS 构建,但注意到我必须更改过滤器。但是如果它不在VS中运行无关紧要,那么它就是另外一回事了。
-
我在这里向 github 添加了一个 repro:github.com/OsirisTerje/ExecutableAsTest 看看这是否适用于您的 VS。然后修改它以匹配你在你的情况下不起作用的任何东西。它适用于 VSTS 构建 :-)
标签: .net unit-testing msbuild azure-devops nunit