首页 文章

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

提问于
浏览
6

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

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

这是我尝试过的:

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

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

> 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内部进行单元测试 .

我如何让两者同时工作?

谢谢!

3 回答

  • 6

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

    我在xunit twitter feed上找到了这个:如果你在VS2017 RC w / .NET Core中尝试使用@xunit,请删除 dotnet-test-xunit 并使用 xunit.runner.visualstudio 2.2 beta 4 .

  • 2

    使用最新的RC.3,我遇到了未被发现的测试问题,并发现当您运行内置的测试资源管理器时,它在输出中表示缺少 Microsoft.DotNet.InternalAbstractions 1.0.0 . 这也是以前版本的.NET Core中的问题,解决方案是相同的,从Nuget安装包 .

  • 7

    执行它时're hitting is present in Preview 3 and fixed in Preview 4. They didn' t逃脱命令行的错误,并且由于dotnet.exe默认安装在 C:\Program Files\dotnet 中,因此总是失败 .

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

相关问题