Gradle:将TestReport任务与不同的XML文件一起使用



我有一个gradle任务,它以XML文件的形式生成测试报告。

build
└── test-results
   ├── test                     // result of the regular unit tests
   │   ├── TEST-SomeTest.xml
   │   └── binary
   │       ├── output.bin
   │       ├── output.bin.idx
  │       └── results.bin
  └── testCustom               // result of my custom task 
      └── TEST-my-lib-1.0.0.SNAPSHOT.xml

我想使用gradle(测试报告(的标准TestReport功能为我的XML结果生成一个HTML报告。

def testCustom = tasks.register('testCustom') {
// This is producing the XML test result. 
}
tasks.register('testCustomReport', TestReport) {
dependsOn testCustom
destinationDir = file("$buildDir/reports/tests/testCustom")
testResultDirs.from(file("$buildDir/test-results/testCustom/"))
}
tasks.named('check') {
dependsOn testCustom, testCustomReport
}

有了这个,我得到了一个空的reports/tests/testCustom文件夹:

build
└── reports
   └── tests
       ├── test
       │   ├── classes
       │   │   └── ... .html
       │   ├── css
       │   │   ├── base-style.css
       │   │   └── style.css
       │   ├── index.html
       │   ├── js
       │   │   └── report.js
       │   └── packages
       │       └── ... .html
       └── testCustom

我想我的自定义TestReport任务配置错误。

我在其他StackOverflow帖子中找到了原因和解决方案:

Gradle TestReport任务似乎依赖于";测试";任务

来自源

因此,它不可能与customTest任务创建的XML一起使用。

另一种选择是使用ant junit库来创建报告,它是有效的。

最新更新