无法使用Visual Studio 2017 RC进行XUnit测试 [英] Can't get XUnit tests working with Visual Studio 2017 RC

查看:96
本文介绍了无法使用Visual Studio 2017 RC进行XUnit测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一生中都无法从基于msbuild的新netcoreapp1.0 xunit项目模板在Visual Studio 2017中进行单元测试.

For the life of me I can't get unit testing working in Visual Studio 2017 from the new msbuild-based netcoreapp1.0 xunit project template.

要求单元测试在Visual Studio内部(对于开发人员)以及从CLI上的dotnet test都可以在自动化构建过程中运行,但是,我不能使两者始终如一地工作.

The requirement is for unit tests to work both inside Visual Studio (for the devs) and from dotnet test on the CLI for the automated build process however, I can't get either working consistently.

这是我尝试过的:

在现有解决方案中,创建一个新项目,然后选择 .NET Core > xUnit Test Project .

In an existing solution, create a new project and select .NET Core > xUnit Test Project.

从Visual Studio构建项目,默认测试出现并成功运行,现在从powershell提示符运行dotnet test,获取:

Build project from Visual Studio, default test appears and runs successfully, now run dotnet test from powershell prompt, get:

 > dotnet test
 Test run for D:\...\bin\Debug\netcoreapp1.0\MyProj.dll(.NETCoreApp,Version=v1.0)
 dotnet exec needs a managed .dll or .exe extension. The application specified was 'C:\Program'

或使用csproj文件进行dotnet测试:

Or dotnet test with csproj file:

 > dotnet test MyProject.csproj
 (same error as above)

 > dotnet test ..\MySolution.sln
 Couldn't find a project to run test from. Ensure a project exists in D:\...
 Or pass the path to the project

如果我添加xunit.runner.consolexunit.runner.msbuild nuget包,它将停止单元测试在Visual Studio内部的工作.

If I add the xunit.runner.console or xunit.runner.msbuild nuget packages, it stops the unit tests working from inside Visual Studio.

我如何同时工作?

谢谢!

推荐答案

您遇到的错误在Preview 3中存在,并在Preview 4中得到修复.它们在执行时以及从dotnet以来都没有转义命令行. exe默认安装在C:\Program Files\dotnet中,它始终会失败.

The bug you're hitting is present in Preview 3 and fixed in Preview 4. They didn't escape the command line when executing it, and since dotnet.exe is installed into C:\Program Files\dotnet by default, it always fails.

如果要继续使用Preview 3,最简单的解决方法是编辑系统PATH环境变量,然后将C:\Program Files\dotnet替换为C:\Progra~1\dotnet.

If you want to continue to use Preview 3, the simplest work-around is to edit your system PATH environment variable, and replace C:\Program Files\dotnet with C:\Progra~1\dotnet.

这篇关于无法使用Visual Studio 2017 RC进行XUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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