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.
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.
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.
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.
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.
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/**/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With