Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
175 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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/**/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...