unit-testing.net-corevisual-studio-2017test-explorer

VS 2017 not discovering tests on .NET Core


can anyone help me get VS2017 to work with .NET Core test projects?

I tried creating both MSTest and xUnit unit test projects for .NET Core from the VS 2017 templates. Neither of them works in the test explorer (not discovered), however running dotnet test from the project folder works fine.

Steps to reproduce:

  1. Create new project in VS 2017
  2. Choose either the Unit Test Project (.NET Core) or xUnit Test Project (.NET Core) template
  3. Implement some arbitrary unit test
  4. Build the solution
  5. Go to the text explorer and try to Run All

At this point the Output window should tell you that 0 test were discovered

.csproj file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
    <PackageReference Include="xunit" Version="2.2.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
  </ItemGroup>

</Project>

If I tried to create a MSTest unit test project from the template that targets .NET Framework (full, not .NET Core), it worked.

Any ideas?


Solution

  • In the end, the problem was solved by changing my system PATH env. variable from C:\Program Files\dotnet\ to C:\Progra~1\dotnet\, as answered in Can't get XUnit tests working with Visual Studio 2017 RC

    Thanks to Alexey for suggesting it in the comments :)