admin管理员组文章数量:1125043
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.
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.
Share Improve this question asked 2 days ago Tim VahlbrockTim Vahlbrock 10110 bronze badges2 Answers
Reset to default 2There 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
As per my knowledge, yes you can filter JUnit tests by tags or annotations directly from the Gradle CLI without modifying the build.gradle
file.
You need to use the --tests
option to specify the test class or method. While for JUnit 5, the --include-tags
option should work for filtering by tags.
An example:
gradle test --tests * --include-tags "yourTag"
Always make sure that you are using JUnit5 and the correct Gradle version that supports this functionality.
版权声明:本文标题:java - Is it possible to filter jUnit Tests on the Gradle CLI WITHOUT modifying the build.gradle? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736654925a1946229.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论