[英]How to recognize what unit testing framework is used in a project in Visual Studio, .NET?
I am working with a Visual Studio C# project and I need to know what unit testing framework is it using, but there is no one to ask about it.我正在处理一个 Visual Studio C# 项目,我需要知道它使用的是什么单元测试框架,但没有人问。
How could I check it?我怎么检查呢?
The most reliable thing here would be to look at the project references that the test project has (either in the IDE by expanding "References" in the solution explorer, or by looking at the csproj directly).这里最可靠的方法是查看测试项目拥有的项目引用(在 IDE 中通过在解决方案资源管理器中展开“引用”,或直接查看 csproj)。 You will probably find something like xunit, nunit, mstest, or something else indicative of what you're using.您可能会发现诸如 xunit、nunit、mstest 之类的东西,或者其他表明您正在使用的东西。
Note that this will often be in addition to Microsoft.NET.Test.Sdk
, which is related to just making it testable;请注意,这通常是Microsoft.NET.Test.Sdk
补充,这与使其可测试有关; for example, I have an xunit project that includes:例如,我有一个 xunit 项目,其中包括:
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
The bottom two are for integration purposes;底部两个用于集成目的; the top one is the actual test framework reference.最上面的一个是实际的测试框架参考。
There are two different things to pay attention to.有两个不同的事情需要注意。
First is the testing framework used in the code.首先是代码中使用的测试框架。 Most common are nUnit, xUnit and MSTest.最常见的是 nUnit、xUnit 和 MSTest。 This is easily checked by looking at references of the project, or installed NuGet packages.这可以通过查看项目的引用或已安装的 NuGet 包轻松检查。
But, Visual Studio needs to be able to discover and run those tests.但是,Visual Studio 需要能够发现并运行这些测试。 For that, each testing framework usually has an adapter that is installed either as visual studio plugin (usually older version) or as a reference or a NuGet package.为此,每个测试框架通常都有一个适配器,可以作为 Visual Studio 插件(通常是旧版本)或作为参考或 NuGet 包安装。 For nUnit, that would be NUnit3TestAdapter or for xUnit Xunit.Runner.VisualStudio .对于 nUnit,这将是NUnit3TestAdapter或 xUnit Xunit.Runner.VisualStudio 。
If you don't care about spending some seconds you should use the official way of determining if a csproj file contains tests:如果您不关心花几秒钟,您应该使用官方方法来确定 csproj 文件是否包含测试:
dotnet test --list-tests <project.csproj>
Related documentationhttps://learn.microsoft.com/en-us/do.net/core/tools/do.net-test相关文档https://learn.microsoft.com/en-us/do.net/core/tools/do.net-test
This will list all the tests in that project without executing them.这将列出该项目中的所有测试而不执行它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.