更新:增加2019年;发现/运行器集成机制与2017年和2015年相同,因此可能出错的关键问题是相同的。
我读过为什么xUnit运行者找不到我的测试,其中包括xUnit永远无法找到你的测试的原因,但我的问题是不同的-我相信我的测试没有微妙的事情发生;(他们在其他环境中工作,这似乎只是我的机器)- Visual Studio 2015[社区版]中的Visual Studio测试运行器根本不显示我的任何测试。我没有做任何令人兴奋的事情;测试的目标是桌面上的xUnit.net v2。
我已经看了输出窗口,并没有看到任何东西在测试下从选项卡显示输出。
还有一个原因可能导致测试资源管理器不显示任何测试,这与Visual Studio 2017 /为. net Core引入的新的可移植的.pdb文件格式有关,这可能会破坏一些VS工具。(背景:参见bug报告“Mono.”Cecil导致OutOfMemoryException与新的.csproj PDBs"。)
您的测试是否因为新的可移植.pdb(调试符号)格式而无法找到?
打开输出窗口。
将显示输出的下拉选择从更改为测试。
如果您看到如下输出(可能在每个测试中都重复一次),那么您就遇到了这个答案中描述的问题:
系统异常。OutOfMemoryException,异常转换<SignatureOfYourTestMethod>
数组尺寸超出支持范围。
如果是,请执行以下步骤解决问题:
Open your test project's Properties (select the test project in Solution Explorer and press Alt+Enter).
Switch to the Build tab.
Click on the Advanced... button (located at the very end of that tab page).
In the drop-down labelled Debugging information, choose none, pdb-only, or full, but NOT portable. It is this last setting that causes the tests to not be found.
Click OK and clean & rebuild your project. If you want to be extra sure, go to your test project's output directory and clean all .pdb files before rebuilding. Now your tests should be back.
这是对我们有效的解决方案。不是最好的,但也许能从中受益。
背景:
我们的脚本是用VS 2013开发的,使用NUnit VS Adapter 2.1..
最近我们迁移到VS 2017,当打开相同的解决方案时,测试将不会在测试资源管理器中显示
在构建时,我们会看到这样的消息:
[Informational] NUnit Adapter 3.10.0.21: Test discovery starting
[Informational] Assembly contains no NUnit 3.0 tests: C:\ihealautomatedTests\SeleniumTest\bin\x86\Debug\SeleniumTest.dll
[Informational] NUnit Adapter 3.10.0.21: Test discovery complete
解决方案(临时):
卸载NUnit Adapter 3.10
安装NUnit VS适配器
现在显示测试。