由于 gradle 4.6 支持具有以下配置的 JUnit 5。
test {
useJUnitPlatform()
}
似乎改变测试实例生命周期的旧方法不起作用。
junitPlatform {
// ...
configurationParameter 'junit.jupiter.conditions.deactivate', '*'
configurationParameters([
'junit.jupiter.extensions.autodetection.enabled': 'true',
'junit.jupiter.testinstance.lifecycle.default': 'per_class'
])
// ...
}
https://junit.org/junit5/docs/current/user-guide/#running-tests-build-gradle-config-params
如何在 gradle 4.6+ 中将 JUnit 5 测试实例生命周期切换为“每类”?
最佳答案
除了使用 eee's answer 中描述的系统属性之外, junit-platform.properties
可以使用文件。 junit-platform.properties
文件可以放入src/test/resources
.
junit-platform.properties
junit.jupiter.testinstance.lifecycle.default = per_class
这是 JUnit 团队的答案。 https://twitter.com/junitteam/status/970014414891094018
Either set it as a systemProperty in the task, or set it in the junit-platform.properties file. The latter is the more robust mechanism since it will be applied in the IDE as well.
关于gradle - 如何在 gradle 4.6+ 中将 JUnit 5 测试实例生命周期切换到 "per-class"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49080099/