Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle test Unit tests - Run all except one or few - Command line

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).

like image 917
AKS Avatar asked Nov 07 '14 20:11

AKS


People also ask

How do I run a specific test in Gradle command line?

single system property can be used to specify a single test. You can do gradle -Dtest. single=ClassUnderTestTest test if you want to test single class or use regexp like gradle -Dtest. single=ClassName*Test test you can find more examples of filtering classes for tests under this link.

How do I run all unit tests in Gradle?

Run Gradle testsIn your Gradle project, in the editor, create or select a test to run. From the context menu, select Run <test name>. icon in the left gutter. If you selected the Choose per test option, IntelliJ IDEA displays both Gradle and JUnit test runners for each test in the editor.

How do I skip a specific test in Gradle?

To skip any task from the Gradle build, we can use the -x or –exclude-task option. In this case, we'll use “-x test” to skip tests from the build. As a result, the test sources aren't compiled, and therefore, aren't executed.

Does Gradle run tests in parallel by default?

Parallel execution Yet Gradle will only run one task at a time by default, regardless of the project structure (this will be improved soon). By using the --parallel switch, you can force Gradle to execute tasks in parallel as long as those tasks are in different projects.


1 Answers

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
like image 93
Mark Vieira Avatar answered Sep 27 '22 21:09

Mark Vieira