.Net Core 2.0 and xUnit doesn't run

女生的网名这么多〃 提交于 2019-12-10 09:45:04

问题


VS2017 + Core 2.0. Created a brand new XUnit test project from template

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

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

EDIT 1: Visual Studio Ver:

dotnet --version
2.0.2

Is it because of Resharper?


回答1:


There are dependencies missing which should be added to get ability to run tests in Visual Studio 2017 and from 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 VS, 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 console and Test Explorer works.

I have created xUnit .NET Core test project from template in Visual Studio 2017 v15.4.2 and everything works out of 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:



来源:https://stackoverflow.com/questions/47163611/net-core-2-0-and-xunit-doesnt-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!