【问题标题】:JUnit5 not generating test-result TEST-*.xml that JUnit4 used toJUnit5 未生成 JUnit4 用于生成的测试结果 TEST-*.xml
【发布时间】:2019-02-05 15:09:03
【问题描述】:

当我在我的项目中使用 JUnit4 时,似乎每次运行测试时,它都会在 app/build/test-result 中生成 TEST-*.xml 报告。 Jenkins 将使用这些 XML 报告来显示每个构建的失败和通过测试。

我在 build.gradle 中用 JUnit5 替换了 JUnit4:

testImplementation "org.junit.jupiter:junit-jupiter-api:5.3.2"

使用 JUnit 5 运行测试时,我不再看到这些 TEST-*.xml 文件正在生成。一旦我回到 JUnit4,它们就是。

这在 JUnit5 中不再可用,还是我必须在每个测试中设置一些东西才能获得这些 XML 报告?

【问题讨论】:

    标签: android junit4 junit5 junit-jupiter


    【解决方案1】:

    找到了解决办法。为了为每个测试生成 XML 报告,您需要在 build.gradle 中包含以下内容:

    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.2'
    

    还有:

    tasks.withType(Test) {
        useJUnitPlatform()
    }
    

    此其他帖子也可能对其他人有用:JUnit5 integration tests with Gradle 4.6

    【讨论】:

    • 我还想在任务块中添加reports { junitXml.setEnabled(true) }
    猜你喜欢
    • 1970-01-01
    • 2023-03-18
    • 2022-10-24
    • 1970-01-01
    • 2011-03-18
    • 1970-01-01
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多