简体   繁体   English

如何在 visual studio 2022 中运行 NUnit 2 测试

[英]How to run NUnit 2 tests in visual studio 2022

I am trying to execute NUnit tests on a legacy project in Visual Studio 2022 professional.我正在尝试在 Visual Studio 2022 专业版中对遗留项目执行 NUnit 测试。 Migrating from NUnit 2 to NUnit 3 is not yet an option, and part of the team works with Visual Studio 2019. The problem I am facing is that the tests are not executed by VS 2022, without any error message on the attempt.从 NUnit 2 迁移到 NUnit 3 还不是一个选项,部分团队使用 Visual Studio 2019。我面临的问题是测试不是由 VS 2022 执行的,尝试时没有任何错误消息。

The test explorer displays the following after executing the test (and the console output finishes with a successful build):执行测试后,测试资源管理器显示以下内容(控制台 output 完成构建成功):

测试资源管理器

The NuGet Package manager had NUnit 2.6.1 already installed. NuGet Package 经理已经安装了 NUnit 2.6.1。 I additionally installed the packets NUnit.Extension.NUnitV2Driver and NUnit.Extension.NUnitV2ResultWriter .我还安装了数据包NUnit.Extension.NUnitV2DriverNUnit.Extension.NUnitV2ResultWriter A test adapter seems only available for NUnit3 ( NUnit3TestAdapter , which I also installed).测试适配器似乎仅适用于 NUnit3( NUnit3TestAdapter ,我也安装了它)。 I enabled all the packages for the individual project as was commented in this question .正如这个问题中评论的那样,我为单个项目启用了所有包。 Is there anything else to install/configure that I could be missing to make this work?是否还有其他要安装/配置的东西我可能会缺少以使其正常工作?

Just a few suggested approaches...只是一些建议的方法......

The NUnit3TestAdapter, as the name indicates, is designed for NUnit 3. While it is able to run NUnit3 tests by use of the NUnitV2Driver extension, I don't think that will work under Visual Studio just by installing the package. You could experiment by modifying the .addins file installed along with the the adapter, but I can't give you precise instructions as I haven't tried it.顾名思义,NUnit3TestAdapter 是为 NUnit 3 设计的。虽然它能够通过使用 NUnitV2Driver 扩展运行 NUnit3 测试,但我认为仅通过安装 package 就无法在 Visual Studio 下运行。您可以通过以下方式进行试验修改与适配器一起安装的.addins文件,但我无法为您提供准确的说明,因为我还没有尝试过。

BTW, the V2 driver extension produces output in V3 format, which is probably what you want for use under Visual Studio.顺便说一句,V2 驱动程序扩展生成 V3 格式的 output,这可能是您想要在 Visual Studio 下使用的格式。 The V2 result writer is only needed if you have a reason to want an output file in V2 format.只有当您有理由想要 V2 格式的 output 文件时,才需要 V2 结果编写器。

I think your best bet may be to try using the last release of the NUnitTestAdapter (ie without '3' in the name), which only works with NUnit V2.我认为您最好的选择可能是尝试使用 NUnitTestAdapter 的最新版本(即名称中没有“3”),它只适用于 NUnit V2。 If it will load under VS2022, it should do exactly what you want.如果它将在 VS2022 下加载,它应该完全按照您的要求执行。 In that case, you should stop loading the two extensions, which the V2 runner doesn't support.在这种情况下,您应该停止加载 V2 运行器不支持的两个扩展。

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

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