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

查看:21
本文介绍了无法使用 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 测试项目.

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:...inDebug
etcoreapp1.0MyProj.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.

如何让两者同时工作?

谢谢!

推荐答案

您遇到的错误存在于预览版 3 中,并在预览版 4 中修复.他们在执行命令行时并没有转义命令行,从 dotnet 开始.exe默认安装在C:Program Filesdotnet中,它总是失败.

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 Filesdotnet by default, it always fails.

如果您想继续使用 Preview 3,最简单的解决方法是编辑您的系统 PATH 环境变量,并替换 C:Program Filesdotnet使用 C:Progra~1dotnet.

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 Filesdotnet with C:Progra~1dotnet.

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

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