.NET Core 2.0和xUnit无法运行

编程入门 行业动态 更新时间:2024-10-23 20:25:48
本文介绍了.NET Core 2.0和xUnit无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

我下载了此样本: github/xunit/xunit.integration

构建 this 解决方案时,我得到:

When building this solution I get:

错误MSB3073命令"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" 用代码退出 1. v2x_netcoreapp20 C:\ Users \ supersuper \ Desktop \ xunit.integration-master \ console \ v2x_netcoreapp20 \ v2x_netcoreapp20.csproj 13

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版本:

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项目来说并不需要,但是通常在控制台和Test Explorer中都可以进行测试.

I have not verified if the second one is required to support VisualStudio. 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.

该项目看起来与众不同:

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>

测试类:

using System; using Xunit; namespace XUnitTestProjectTmpl { public class UnitTest1 { [Fact] public void Test1() { } } }

测试结果:

更多推荐

.NET Core 2.0和xUnit无法运行

本文发布于:2023-11-14 00:47:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585763.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Core   NET   xUnit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!