Gradle 配置 TestNG 和 JUnit 报告目录

Gradle configuring TestNG and JUnit reports dirs

我对 gradle 比较陌生,我们在项目中同时使用 JUnit 和 testNG 单元测试。在 google 的帮助下,我弄清楚了如何进行 testNG 和 JUnit 测试 运行。以下是我最终实现它的方式

build.gradle
....    
task testNG(type: Test) {
    useTestNG {}
}

test {
    dependsOn testNG
}

但是只生成了 JUnit 报告。 Google 再次帮助我 link https://discuss.gradle.org/t/using-junit-and-testng-together-steps-on-testng-html-file/5484 它展示了如何通过配置两个单独的测试报告文件夹来解决与我的问题完全相同的问题,如下所示:

testng.testReportDir = file("$buildDir/reports/testng")
test.testReportDir = file("$buildDir/reports/testjunit")

但是它并没有确切说明将这两个条目放在哪里,我觉得我会疯狂地尝试查看 gradle 书籍、gradle 示例和 API不知道怎么做。根据 API test 任务有一个 reports 属性,您可以在其中配置 TestTaskReports 实例,但无论我尝试什么都失败了。 你能帮我解决这个问题吗?它一定是太明显了,我错过了它。

提前致谢

查看 Test. There you can find a reports property at https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:reports 的 DSL 参考 这为您提供了 DSL 中的 TestTaskReports. Following this route 引导您:

task testNG(type: Test) {
    useTestNG {}
    reports.html.destination = file("$buildDir/reports/testng")
}

test {
    reports.html.destination = file("$buildDir/reports/test")

    dependsOn testNG
}