使用 junitPlatform 时设置系统属性

Setting system properties when using junitPlatform

我无法找到在使用 Gradle 执行 JUnit 5 测试时如何设置系统属性。标准 test 任务可以配置如下:

test {
     systemProperty 'org.slf4j.simpleLogger.defaultLogLevel', 'warn'
}

然而,junitPlatform任务似乎没有这样的选项。

更新:

请注意,由 JUnit 团队开发的 junit-platform-gradle-plugin 在 JUnit 平台 1.2 中已弃用,并在 1.3 中停产。请在 Gradle 4.6 或更高版本中切换到 Gradle 的标准 test 任务。详情 here.


正如我提到的 here,如果您仍在使用过时的 junit-platform-gradle-plugin,您可以像这样设置系统属性:

afterEvaluate {
    def junitPlatformTestTask = tasks.getByName('junitPlatformTest')

    junitPlatformTestTask.systemProperty 'org.slf4j.simpleLogger.defaultLogLevel', 'warn'
}