3

Visual Studio 2017 + .NET Core 2.0. I created a brand new xUnit test project from the template:

Project (.csproj) file:

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

      <PropertyGroup>
        <TargetFramework>netcoreapp2.0</TargetFramework>

        <IsPackable>false</IsPackable>
      </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
    <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
    <PackageReference Include="xunit" Version="2.3.1" />
    <PackageReference Include="xunit.runner.console" Version="2.3.1" />
  </ItemGroup>

    </Project>

Test

public class Class1
{
    [Fact]
    public void Test1()
    {
        Assert.Equal(1, 1);
    }
}

Whenever running or debugging tests I get "Inconclusive: Test not run". What am I missing?

I downloaded this sample: https://github.com/xunit/xunit.integration

When building this solution I get:

Error MSB3073 The command "dotnet "C:\Users\supersuper.nuget\packages\xunit.runner.console\2.3.1\build..\tools\netcoreapp2.0\xunit.console.dll" "C:\Users\supersuper\Desktop\xunit.integration-master\console\v2x_netcoreapp20\bin\Debug\netcoreapp2.0\v2x_netcoreapp20.dll"" exited with code 1. v2x_netcoreapp20 C:\Users\supersuper\Desktop\xunit.integration-master\console\v2x_netcoreapp20\v2x_netcoreapp20.csproj 13

Visual Studio version:

Enter image description here

dotnet --version
2.0.2

Enter image description here

Is it because of ReSharper?

Enter image description here

TylerH
  • 20,799
  • 66
  • 75
  • 101
ShaneKm
  • 20,823
  • 43
  • 167
  • 296
  • Try xunit.analyzers project and run tests which are there. The project you have downloaded xunit.integration should not be run on .Net Core as it tests integration of xUnit VS extension.. – Jacek Blaszczynski Nov 07 '17 at 18:36
  • ok, forget the sample then. All i'm trying to do is run xUnit in Core 2. Please see my Test class – ShaneKm Nov 07 '17 at 19:03
  • It could be that you have an old version of VS 2017. See my edited answer for current RTM v15.4.2 template – Jacek Blaszczynski Nov 07 '17 at 19:27
  • I am running ver 15.4.2 - please see Edit1 – ShaneKm Nov 07 '17 at 19:35
  • Try to install .NET Core SDK 2.0 for both x86 and x64. When you run tests VS selects by default x86 architecture and if you are missing .NET Core SDK 2.0 than that could be a reason I guess. – Jacek Blaszczynski Nov 07 '17 at 19:48
  • This is a Resharper issue: https://stackoverflow.com/questions/45775440/resharper-xunit-tests-not-working-after-installing-net-core-2-0 – ShaneKm Nov 07 '17 at 21:35

1 Answers1

5

There are dependencies missing which should be added to get the ability to run tests in Visual Studio 2017 and from the console:

    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
    <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
    <PackageReference Include="xunit.runner.console" Version="2.3.1" />

I have not verified if the second one is required to support Visual Studio. Nevertheless, my tests run from Test Explorer and show detailed run results. There are some issues with vstest.descoveryengine.exe which is not needed for MSTest v2 projects, but in general testing from both the console and Test Explorer works.

I have created an xUnit .NET Core test project from the template in Visual Studio 2017 v15.4.2 and everything works out of the box.

The project looks different:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
    <PackageReference Include="xunit" Version="2.2.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
  </ItemGroup>

</Project>

Test class:

using System;
using Xunit;

namespace XUnitTestProjectTmpl
{
    public class UnitTest1
    {
        [Fact]
        public void Test1()
        {

        }
    }
}

Test result:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jacek Blaszczynski
  • 3,183
  • 14
  • 25
  • I've copied your csproj and still no go = "Test not run". It finds the tests but will not run them. Have you run Assert? – ShaneKm Nov 07 '17 at 19:36
  • 1
    @ShaneKm R# Unit Test Runner differs from built-in VS runner and has a lot of issues with xUnit tests. So it really can be because of R#. – Ilya Chumakov Nov 07 '17 at 20:05
  • Solved: This is because of Resharper. Running tests by Test => Run Works!. Thank you – ShaneKm Nov 07 '17 at 20:21