Is there a way to build custom test phases in gradle?
I have a series of tests, namely
/unit
/local
/remote
which is running JUnit managed tests for a couple different purposes. I’d love to be able to run these as test phases, such as gradle test:unit, or something like that. Ideally, I could also specify a description for each test phase, so gradle tasks describes the role of each of the tests.
Is this possible? If so, how?
I tried this:
sourceSets {
unit {
java.srcDir file('src/test/groovy/local')
resources.srcDir file('src/local/resources')
}
}
dependencies {...}
task unitTest(type: Test){
testClassesDir = sourceSets.local.output.classesDir
classpath = sourceSets.local.runtimeClasspath
}
…as copied from withIntegrationTests in the provided samples, but when I run gradle unitTest, no tests run.
You just need to add three
Testtasks (testUnit,testLocal,testRemote) and configure them accordingly. (Instead of introducingtestUnit, you could also reuse thetesttask that comes with the Java plugin.) If the sources are in different source folders, it also makes sense to add additional source sets. For the details, have a look atsamples/java/withIntegrationTestsin the full Gradle distribution.