gradle - 如何在 gradle 4.6+ 中将 JUnit 5 测试实例生命周期切换到 "per-class"?

标签 gradle junit5

由于 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/

相关文章:

maven - 防止在项目中使用 junit4 库

java - Karate :使用 JUnit5 的运行者类(class)

android - 在Appium上执行测试期间调试应用程序代码

java - gradle CompileJava任务不遵守(source | target)Compatibility属性,java.lang.UnsupportedClassVersionError:主要版本错误

java - StringBuilder 损坏(内部字段 `count` = 0)

java - JUnit 断言抛出中的可执行文件会发生什么情况?

java - Spring Boot WebMvcTest 需要 EntityManager

java - 在 Windows 10 (Intellij IDEA) 上使用 gradle 项目安装 Google or-tools

安卓工作室 3.5 错误 : Unable to resolve dependency for ':app@debug/compileClasspath'

java - 使用 Gradle 调试/发布 Java 构建的示例?