我正在尝试在 Visual Studio 2017 中使用新的基于 msbuild 的 netcoreapp1.0
xunit 项目模板进行单元测试,但一直无法成功。
需求是让单元测试在 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 test:
> 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.console
或者 xunit.runner.msbuild
的nuget包,就会导致从Visual Studio内部停止运行单元测试。我该如何同时让它们都起作用呢?
谢谢!