.NET Core 1.0-如何运行“解决方案中的所有测试”使用xUnit命令行 [英] .NET Core 1.0 - How to run "All tests in Solution" with xUnit command line

查看:98
本文介绍了.NET Core 1.0-如何运行“解决方案中的所有测试”使用xUnit命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

xUnit.net入门(.NET Core /ASP.NET Core) 页介绍了如何使用 dotnet测试命令行运行测试。

The Getting started with xUnit.net (.NET Core / ASP.NET Core) page describes how to run tests with dotnet test command line.

它声明它需要一个特定的 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:\git\Project\test [master ≡]> dotnet test
dotnet-test Error: 0 : System.InvalidOperationException: C:\git\Project\test\project.json does not exist.
   at Microsoft.DotNet.Tools.Test.TestCommand.GetProjectPath(String projectPath)
   at Microsoft.DotNet.Tools.Test.TestCommand.DoRun(String[] args)
C:\git\Project\test [master ≡]>

问题:有没有一种方法可以运行所有测试(多个 project.json )进行一次 dotnet测试

Question: Is there a way to run all tests (multiple project.json) with a single dotnet test?

推荐答案

一个月没有答案,我至少会分享我一直在做的事情。 (一旦启动Visual Studio 15 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)

只需使用 for 循环在所有project.json上:

Simply using a for loop on all project.json:

在本地,从 test 目录运行:

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屋!

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