5
votes

I have just upgraded my Project to .Net Core 1.1 and all my tests are not discovered now. It was working fine when it was in the old version (.Net Core 1.0)

The following is the message in VS 2015 Output Window generated by XUnit

------ Discover test started ------
Discovering tests in 'C:\TW\websites2016\AssetsDB\src\Tests\project.json' ["C:\Program Files\dotnet\dotnet.exe" test "C:\TW\websites2016\AssetsDB\src\Tests\project.json" --output "C:\TW\websites2016\AssetsDB\src\Tests\bin\Debug\netcoreapp1.1" --port 61778 --parentProcessId 7316 --no-build]
'test-xunit' returned '-532462766'.
========== Discover test finished: 0 found (0:00:01.7697049) ==========

Codes in project.json

{
  "version": "1.0.0-*",
  "testRunner": "xunit",

  "dependencies": {
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "AssetsDB": { "target": "project" },
    "xunit": "2.2.0-beta4-build3444",
    "dotnet-test-xunit": "2.2.0-preview2-build1029",
  },

  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        }
      },
      "imports": [
        "dotnet5.4",
        "portable-net451+win8"
      ]
    }
  }
}

My Sample Test:

namespace Tests
{
    public class QueryPagingAssetsTest
    {
        [Fact]
        public void should_return_PagingAssetItems()
        {
             Assert.True(xxxxx);
        }
    }
}

Is there anything I am missing? Do I need to change anything to make it compatible with .Net Core 1.1?

UPDATED: Working Version of project.json

You need to add InternalAbstractions library. If you follow Brad's link, it will tell you to use "xunit.runner.visualstudio" instead of "xunit.runner.visualstudio". But AFAIK, it's not working yet (as of 09/12/2016)

"dependencies": {
    "AssetsDB": { "target": "project" },
    "Microsoft.DotNet.InternalAbstractions": "1.0.1-beta-003206",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "xunit": "2.2.0-beta4-build3444",
    "dotnet-test-xunit": "2.2.0-preview2-build1029"
    //"xunit.runner.visualstudio": "2.2.0-beta4-build1194"
  },
3

3 Answers

6
votes

Add "Microsoft.DotNet.InternalAbstractions": "1.0.0" to your dependencies, dotnet-test-xunit has issues with .NET Core 1.1 (and is apparently due to be retired when the new csproj-based tooling is out). Check out https://github.com/xunit/xunit/issues/1031#issuecomment-261374279.

1
votes

I am using NUnit and the following solved my problem: Installing Microsoft.DotNet.InternalAbstractions, closing Visual Studio, delete project.lock.json, open Visual Studio, compile and run tests

1
votes

Creating Unit-Tests with ASP.NET Core 1.1, xUnit and ReSharper

My current environment:

  • Windows 10 64bit
  • Visual Studio Enterprise 2017 15.1 (26403.7) Release
  • ReSharper 2017.1.2

After I created a project with dotnet new xunit, I was able to create tests and run it with ReSharper Unit Test Session.

.csproj

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

  <ItemGroup>
    <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
  </ItemGroup>

</Project>

UnitTest.cs

using Xunit;

namespace ErpWebApi.UnitTests
{
   public class UnitTest1
   {
        [Fact]
        public void TestFail()
        {
            Assert.Equal(2, 3);
        }

        [Fact]
        public void TestSucess()
        {
            Assert.Equal(2, 2);
        }
    }
}

Result:

See image only with hyperlink, no rep

Reference to Microsoft