Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: how to exclude some tests?

My src/test/ folder includes both unit and functional tests. The classpath of functional tests has the word cucumber, whereas the unit tests do not. So, how can I run the unit tests only?

Thank you very much.

P.S.: I know it is easy to use the "include" logic to select tests. For example, to only run the functional tests in my case, I can simply use this
./gradlew test -Dtest.single=cucumber/**/
However, I don't know how to exclude tests in a simple way.

BTW, I am using gradle 1.11.

like image 708
JBT Avatar asked Mar 05 '14 21:03

JBT


People also ask

How do you exclude specific classes in dependency Gradle?

If you just want to exclude one class for a dependency jar, take a look at the jar jar links tool and its Gradle plugin. It allows you to alter included jars, e.g. to change packages or remove classes.

How do you exclude a test class?

If you want to ignore a test method, use @Ignore along with @Test annotation. If you want to ignore all the tests of class, use @Ignore annotation at the class level.

How do I run a specific test in Gradle?

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 skip a Gradle test in IntelliJ?

You can skip test using following settings. You can get to this via Gradle panel located at right top corner. Select task -> Run Configuration -> Right click -> Edit Run Configuration.. Show activity on this post.


1 Answers

Credit: This answer is inspired by JB Nizet's answer. It is posted because it is more direct to my question.

To run the unit tests only, create a new task like this:

task unitTest( type: Test ) {     exclude '**/cucumber/**' } 

This way we have:
run all tests: ./gradlew test
run all unit tests: ./gradlew unitTest
run all functional tests: ./gradlew test -Dtest.single=cucumber/**/

like image 57
JBT Avatar answered Sep 19 '22 08:09

JBT