.NET Core 2.0 和 xUnit 不运行 [英] .NET Core 2.0 and xUnit doesn't run

查看:51
本文介绍了.NET Core 2.0 和 xUnit 不运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio 2017 + .NET Core 2.0.我从模板创建了一个全新的 xUnit 测试项目:

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

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

测试

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?

我下载了这个示例:https://github.com/xunit/xunit.integration

在构建这个解决方案时,我得到:

When building this solution I get:

错误 MSB3073 命令dotnetC:Userssupersuper.nugetpackagesxunit.runner.console2.3.1uild.. ools etcoreapp2.0xunit.console.dll""C:UserssupersuperDesktopxunit.integration-masterconsolev2x_netcoreapp20inDebug etcoreapp2.0v2x_netcoreapp20.dll""用代码退出1. v2x_netcoreapp20 C:UserssupersuperDesktopxunit.integration-masterconsolev2x_netcoreapp20v2x_netcoreapp20.csproj 13

Error MSB3073 The command "dotnet "C:Userssupersuper.nugetpackagesxunit.runner.console2.3.1uild.. ools etcoreapp2.0xunit.console.dll" "C:UserssupersuperDesktopxunit.integration-masterconsolev2x_netcoreapp20inDebug etcoreapp2.0v2x_netcoreapp20.dll"" exited with code 1. v2x_netcoreapp20 C:UserssupersuperDesktopxunit.integration-masterconsolev2x_netcoreapp20v2x_netcoreapp20.csproj 13

Visual Studio 版本:

Visual Studio version:

dotnet --version
2.0.2

是因为 ReSharper 吗?

Is it because of ReSharper?

推荐答案

缺少依赖项,应添加这些依赖项以获得在 Visual Studio 2017 和控制台中运行测试的能力:

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

我还没有验证是否需要第二个来支持 Visual Studio.尽管如此,我的测试从测试资源管理器运行并显示详细的运行结果.vstest.descoveryengine.exe 存在一些问题,MSTest v2 项目不需要它,但一般来说,控制台和测试资源管理器的测试都有效.

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.

我从 Visual Studio 2017 v15.4.2 中的模板创建了一个 xUnit .NET Core 测试项目,一切都开箱即用.

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.

项目看起来不一样:

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

测试类:

using System;
using Xunit;

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

        }
    }
}

测试结果:

这篇关于.NET Core 2.0 和 xUnit 不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆