The API for test adapters for .NET Core has changed with the release of Visual Studio 2017 and the transition from the project.json format to the csproj format. This made existing dotnet-test-* adapters like dotnet-test-nunit obsolete.
The adapters have been updated, but the way to install and run tests in Visual Studio or on the command line using dotnet test requires different references in your test projects. Beware of any documentation that you find reference packages are in dotnet-test-* format, as they are outdated.
First, your test project should target a specific .NET Framework or .NET Framework. It cannot target .NET Standard , even if the code you are testing is .NET Standard. This is because the purpose of the tests indicates which platform the tests will run on. The .NET Standard is similar to the PCL (Portable Class Library) because it can run on many platforms.
Then you need to add links to Microsoft.NET.Test.Sdk , your test structure and a compatible test adapter. For NUnit, your links will look like this:
<itemgroup> <packagereference Include="Microsoft.NET.Test.Sdk" Version="15.0.0"></packagereference> <packagereference Include="NUnit" Version="3.7.1"></packagereference> <packagereference Include="NUnit3TestAdapter" Version="3.8.0"></packagereference> </itemgroup>
The comment above mentions the addition,
<ItemGroup> <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> </ItemGroup>
This is not strictly required, but can help. It is automatically added to all unit test projects in Visual Studio to quickly find projects with tests.
If your tests do not appear in Visual Studio, the first thing to try is to close your solution and then open them again. It seems that errors in Visual Studio do not detect changes in projects when they are edited.
See Testing .NET Core with NUnit in Visual Studio 2017 for more information.
Rob Prouse May 16 '17 at 12:30 2017-05-16 12:30
source share