使用gradle和junit 5设置常规的build
命令以运行所有测试:
test {
useJUnitPlatform()
failFast = true
}
我还用
@Tag("slow")
有时要跳过的一些测试,因此我有一个新任务testFast
来跳过这些测试:task testFast(type: Test) {
useJUnitPlatform {
excludeTags 'slow'
}
}
大。因此,现在我需要一个附加的
build
命令,该命令执行与常规build命令相同的步骤,但用test
命令替换了常规的testFast
步骤。我该怎么做呢?task buildFast(dependsOn: 'build') {
// TODO replace the test task with testFast
}
最佳答案
您可能可以通过TaskExecutionGraph完成此操作
task buildFast(dependsOn: 'build') {
// no body required
}
gradle.taskGraph.whenReady {
boolean fast = gradle.taskGraph.hasTask('buildFast')
project.tasks['test'].enabled = !fast
project.tasks['testFast'].enabled = fast
}
关于gradle - 使用junit5自定义构建任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50092090/