我想执行标记的 JUnit 5 测试,例如。只有缓慢的测试,使用 gradle。
我想在 maven 中做同样的事情:
mvn test -Dgroups="slow"
但是 gradle 中的等价物是什么?或者什么都没有?
执行所有标有
@Tag("slow")
的 JUnit 5 测试.我知道创建这样的专用任务非常简单:tasks.withType(Test::class.java).configureEach {
useJUnitPlatform() {
includeTags("slow")
}
}
但是我有很多不同的标签,我不想为每个标签都指定一个任务。或者更糟的是,对所有排列都有一项任务。
另一种可能性是将自定义属性传递给这样的任务
tasks.withType(Test::class.java).configureEach {
val includeTagsList = System.getProperty("includeTags", "")!!.split(",")
.map { it.trim() }
.filter { it.isNotBlank() }
if (includeTagsList.isNotEmpty()) {
includeTags(*includeTagsList.toTypedArray())
}
}
最佳答案
我上次检查时,Gradle 没有内置支持通过命令行配置 JUnit 平台包含和排除标记,因此您必须采用第二种方法。
但是……不需要拆分、映射和过滤标签:只需使用标签表达式:https://junit.org/junit5/docs/current/user-guide/#running-tests-tag-expressions
关于gradle - 如何在gradle cmd中包含/排除junit5标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60474190/