您必须安装 NUnit VSAdapter vsix 扩展,或将适配器作为 nuget 包添加到您的解决方案中。
最新版本是 2.0,vsix 可以在这里找到:https://visualstudiogallery.msdn.microsoft.com/6ab922d0-21c0-4f06-ab5f-4ecd1fe7175d https://visualstudiogallery.msdn.microsoft.com/6ab922d0-21c0-4f06-ab5f-4ecd1fe7175d
nuget 包可以在这里找到:http://www.nuget.org/packages/NUnitTestAdapter/ http://www.nuget.org/packages/NUnitTestAdapter/
有关这些选项的更多信息,请参阅此 MSDN ALM 帖子http://blogs.msdn.com/b/visualstudioalm/archive/2013/06/11/part-3-unit-testing-with-traits-and-code-coverage-in-visual-studio-2012-using- tfs-build-and-the-new-nuget-adapter-approach.aspx http://blogs.msdn.com/b/visualstudioalm/archive/2013/06/11/part-3-unit-testing-with-traits-and-code-coverage-in-visual-studio-2012-using-the-tfs-build-and-the-new-nuget-adapter-approach.aspx,这也指向之前的两篇文章。
如果您查看“测试”下的“输出控制台”窗口,适配器名称和版本会在运行时显示在那里。如果它没有出现,则适配器未处于活动状态。
如果您运行 Resharper,请确保您拥有最新的 8.2 版本,之前与测试适配器和 resharper 存在冲突。
即使您无法将此项目从 NUnit 2.5.9 升级到最新的 2.6.4,您也可以使用 2.6.4 在测试项目中验证适配器是否正常工作。
我刚刚使用 NUnit 2.5.9 在我自己的机器上进行了检查,这与 2.0 适配器配合得很好。
Update:
对于 VS2017,您无需安装 NUnit VSAdapter vsix 扩展,而是安装适用于 Visual Studio 2012(更新 1)的 NUnit 3 TestAdapter。这适用于 NuGet 包:NUnit 3.9.0。
更新 2 - 2019 年 6 月刚刚发布了 NUnit2 Adapter 的 2.2 版本。它现在应该可以与 SDK 类型项目以及 VS 2017 和 2019 正常工作。