无法使用 Visual Studio 2017 RC 进行 XUnit 测试

Can't get XUnit tests working with Visual Studio 2017 RC

对于我的生活,我无法在 Visual Studio 2017 年从新的基于 msbuild 的 netcoreapp1.0 xunit 项目模板进行单元测试。

要求单元测试在 Visual Studio(对于开发人员)和 CLI 上的 dotnet test 内工作以进行自动构建过程,但是,我无法始终如一地工作.

这是我尝试过的:

在现有解决方案中,创建一个新项目和select .NET Core > xUnit Test Project.

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

 > 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 测试:

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

如何让两者同时工作?

谢谢!

我知道这不是一个很好的答案,但 dotnet-test-xunit 只支持 project.json 文件。 VS 2017 强制您切换到 csproj 文件。

我在 xunit 推特上发现了这个: 如果您尝试在带有 .NET Core 的 VS2017 RC 中使用 @xunit,请删除 dotnet-test-xunit 并改用 xunit.runner.visualstudio 2.2 beta 4。

您遇到的错误存在于预览版 3 中并在预览版 4 中得到修复。它们在执行时没有转义命令行,并且由于 dotnet.exe 已安装到 C:\Program Files\dotnet默认,它总是失败。

如果您想继续使用预览版 3,最简单的解决方法是编辑您的系统 PATH 环境变量,并将 C:\Program Files\dotnet 替换为 C:\Progra~1\dotnet

使用最新的 RC.3 我遇到了未发现测试的问题,并且发现当您 运行 built-in 测试资源管理器时它在输出中说 Microsoft.DotNet.InternalAbstractions 1.0.0 不见了。 .NET Core之前的版本也有这个问题,解决办法是一样的,从Nuget安装包。