Gradlle测试单元测试 - 除一个或几个之外运行所有命令行 [英] Gradlle test Unit tests - Run all except one or few - Command line

查看:432
本文介绍了Gradlle测试单元测试 - 除一个或几个之外运行所有命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中有一堆JUnit单元测试。构建系统是Gradle。操作系统:Windows / Linux。



测试(单元测试)在Gradle中自由运行,即如果运行 gradle clean build ,Gradle也会运行测试任务(运行单元测试)。我知道如何运行测试文件夹中的所有测试,在命令行的特定测试。例如:请参阅Gradle用户指南中的23.13.3和23.13.4节: http://www.gradle.org/docs/current/userguide/java_plugin.html#sec:java_test



我的问题:



我想运行所有测试,除了一个或一些。我如何在Gradle中在命令行(而不是使用在test {...}部分在build.gradle或更高级别.gradle文件中的排除)。

解决方案

您可以有条件地根据属性值添加排除。

  {
if(project.hasProperty('excludeTests')){
exclude project.property('excludeTests')
}
}



然后,您可以从命令行执行此类操作。

  $ gradle -PexcludeTests = org.foo.MyTest build 


I have bunch of JUnit unit tests in my projects. Build system is Gradle. OS: Windows/Linux.

Test (Unit tests) come free in Gradle i.e. if you run "gradle clean build" Gradle will also run "test" task (to run your Unit tests). I know how can I run all tests in a test folder, of a specific test at command line. Ex: See 23.13.3 and 23.13.4 sections in Gradle user guide: http://www.gradle.org/docs/current/userguide/java_plugin.html#sec:java_test

My question:

I want to run all tests except one or some. How can I do this in Gradle at command line (rather than using exclude(s) within test { ... } section in build.gradle or higher level .gradle file).

解决方案

You could conditionally add an exclusion based on a property value.

test {
    if (project.hasProperty('excludeTests')) {
        exclude project.property('excludeTests')
    }
}

You could then do something like this from the command line.

$ gradle -PexcludeTests=org.foo.MyTest build

这篇关于Gradlle测试单元测试 - 除一个或几个之外运行所有命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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