.NET Core 1.0 - 如何运行“解决方案中的所有测试"使用 xUnit 命令行 [英] .NET Core 1.0 - How to run "All tests in Solution" with xUnit command line
问题描述
开始使用 xUnit.net (.NET Core/ASP.NET Core) 页面描述了如何使用 dotnet test
命令行运行测试.
它声明它需要一个特定的 project.json,我们在其中添加 xunit 依赖项和测试运行器:
It states that it requires a specific project.json, where we add xunit dependencies and test runner:
"testRunner": "xunit",
"dependencies": {
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-build10015"
}
如果我尝试从父目录调用它:
If I try calling it from the parent directory:
C:gitProject est [master ≡]> dotnet test
dotnet-test Error: 0 : System.InvalidOperationException: C:gitProject estproject.json does not exist.
at Microsoft.DotNet.Tools.Test.TestCommand.GetProjectPath(String projectPath)
at Microsoft.DotNet.Tools.Test.TestCommand.DoRun(String[] args)
C:gitProject est [master ≡]>
问题:有没有办法用一个 dotnet 测试
运行所有测试(多个 project.json)?
Question: Is there a way to run all tests (multiple project.json) with a single dotnet test
?
推荐答案
由于已经快一个月没有人回答了,我至少会分享我一直在做的事情.(一旦 Visual Studio15"RTM 启动,这将无关紧要,因为 project.json 已死)
Since it's been almost a month and no answer, I'll at least share what I've been doing. (this won't be relevant once Visual Studio "15" RTM is launched because project.json is dead)
只需在所有 project.json 上使用 for
循环:
Simply using a for
loop on all project.json:
在本地,从 test 目录,我只运行:
Locally, from the test directory, I just run:
for /f %a in ('dir /b /s project.json ^| find /v "TestUtilities"') do dotnet test %a
在所有 project.json 上运行它,除了路径有:TestUtilities
Running it on all project.json except where the path has: TestUtilities
请注意,在 TeamCity 上,您需要转义 %(并且在脚本中您需要加倍:%%)所以它过去了:
Mind that on TeamCity you need to escape % (and in scripts you need double: %%) so it goes by:
for /f %%%a in ('dir /b /s project.json ^| find /v "TestUtilities"') do dotnet test %%%a
注意 %%%.由于 TeamCity 中的 % 用于变量,因此第三个 % 对其进行了转义.
Note the %%%. Since % in TeamCity is used for variables, the third % escapes it.
这篇关于.NET Core 1.0 - 如何运行“解决方案中的所有测试"使用 xUnit 命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!