使用junitPlatform时设置系统属性

6

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

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

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

1个回答

12

更新:

请注意,JUnit团队开发的junit-platform-gradle-plugin已在JUnit Platform 1.2版本中被弃用,并在1.3版本中停止使用。请在Gradle 4.6或更高版本中切换到Gradle的标准test任务。详情请见此处


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

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

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

不用谢!我也刚刚在这里链接了JGiven:https://github.com/junit-team/junit5/issues/297 - Sam Brannen
非常感谢。我不知道在Junit 5相关问题上浪费了多少时间。 - Johannes Barop

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接