简体   繁体   中英

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.

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). You will probably find something like xunit, nunit, mstest, or something else indicative of what you're using.

Note that this will often be in addition to Microsoft.NET.Test.Sdk , which is related to just making it testable; for example, I have an xunit project that includes:

    <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. This is easily checked by looking at references of the project, or installed NuGet packages.

But, Visual Studio needs to be able to discover and run those tests. 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. For nUnit, that would be NUnit3TestAdapter or for 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:

dotnet test --list-tests <project.csproj>

Related documentationhttps://learn.microsoft.com/en-us/do.net/core/tools/do.net-test

This will list all the tests in that project without executing them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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