does anyone know, whether it is possible to only execute JUnit Tests with specific Tags or annotations, by specifying that on the Gradle CLI without having to specify it in the build file? This article suggests there is a --include-tags
option, but Gradle wouldn't accept it.
Background is that I want to create pipeline templates for a specific type of test that will use an annotation I provided. On the annotation I can add the required JUnit Tag. I don't want the projects using the templates having to keep their build file in sync with the pipeline templates.
There is indeed no such argument --include-tags
for Gradle, the article is misleading. You can however implement this behavior with a Gradle configuration similar to this (in Kotlin):
tasks.test {
useJUnitPlatform()
if (project.hasProperty("includeTags")) {
useJUnitPlatform {
includeTags(*project.property("includeTags").toString().split(",").toTypedArray())
}
}
}
Or, in Groovy:
project.tasks.named("test") {
useJUnitPlatform()
if (project.hasProperty('includeTags')) {
useJUnitPlatform {
includeTags project.property('includeTags').split(",")
}
}
}
Then you could run your tests as follows:
gradle test -PincludeTags=tag1,tag2