Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS 2017 not discovering tests on .NET Core

Tags:

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?

like image 419
valorl Avatar asked Mar 12 '17 13:03

valorl


People also ask

How do I open .NET core in VS 2017?

Run Visual Studio 2017 and Select File > New Project. On the left menu select Visual C# > . NET Core. On the list of application templates pick ASP.NET Core Web Application.

How do I run a test in Visual Studio 2017?

Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.

How do I enable test in Visual Studio?

To enable Live Unit Testing, select Test > Live Unit Testing > Start from the top-level Visual Studio menu.


1 Answers

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 :)

like image 162
valorl Avatar answered Dec 31 '22 20:12

valorl