使用 gradle 启用 junit 扩展自动检测

Enable junit extensions autodetection with gradle

我想在我的项目上默认启用 junit 扩展自动检测 如果我理解我应该在启动构建时使用 -Djunit.jupiter.extensions.autodetection.enabled=true。

但我想在命令行和我的所有子模块中默认启用而无需额外参数。

我觉得这样的东西应该不错:

allprojects {
    test {
        //put an option here
        useJUnitPlatform()
    }

}

但我不知道在 build.gradle 中放入哪个选项。

在Gradle中您可以使用系统属性扩展:

test {
    // ...
    systemProperty("junit.jupiter.extensions.autodetection.enabled", true)
}

有关详细信息,请参阅 JUnit 5 User Guide