如何将JUnit 5测试实例生命周期切换到;每班;在gradle 4.6+;?
As gradle 4.6通过以下配置支持JUnit 5如何将JUnit 5测试实例生命周期切换到;每班;在gradle 4.6+;?,gradle,junit5,Gradle,Junit5,As gradle 4.6通过以下配置支持JUnit 5 test { useJUnitPlatform() } 似乎改变testinstance生命周期的旧方法不起作用 junitPlatform { // ... configurationParameter 'junit.jupiter.conditions.deactivate', '*' configurationParameters([ 'junit.jupiter.extension
test {
useJUnitPlatform()
}
似乎改变testinstance生命周期的旧方法不起作用
junitPlatform {
// ...
configurationParameter 'junit.jupiter.conditions.deactivate', '*'
configurationParameters([
'junit.jupiter.extensions.autodetection.enabled': 'true',
'junit.jupiter.testinstance.lifecycle.default': 'per_class'
])
// ...
}
如何在gradle 4.6+中将JUnit 5测试实例生命周期切换为“每类”?您可以使用系统属性执行此操作:
test {
useJUnitPlatform {
// ...
systemProperty 'junit.jupiter.testinstance.lifecycle.default', 'per_class'
// ...
}
}
除了使用中所述的系统属性外,还可以使用junit platform.properties文件<代码>junit平台。属性文件可以放在
src/test/resources
中
junit平台.属性
junit.jupiter.testinstance.lifecycle.default = per_class
以下是JUnit团队的答案
在任务中将其设置为systemProperty,或在
junit-platform.properties文件。后者更为稳健
机制,因为它也将应用于IDE中
谢谢,它很有效。我还发布了另一个解决方案。