Gradle合并Junit报告 [英] Gradle Merge Junit Report

查看:48
本文介绍了Gradle合并Junit报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gradle中是否有一种方法可以将junit xml报告合并到单个测试报告文件中.

Is there a way in gradle that the junit xml report can be merged into a single test report file.

当我们在ant中使用cp-suite执行IntegrationTestSuite.java时,将只有一个junit报告.在gradle上创建了多个junit报告.

When we executed our IntegrationTestSuite.java with cp-suite in ant there is a single junit report. On gradle multiple junit reports are created.

IntegrationTestSuite.java

@RunWith(Categories.class)
@Categories.IncludeCategory(IntegrationTests.class)
@Categories.ExcludeCategory(DebugJenkinsTests.class)
@Suite.SuiteClasses(AllTestSuite.class)
public class IntegrationTestSuite { /* nop */
}

build.xml

<junit>
   <formatter type="xml" />
      <batchtest todir="${testreport.dir}">
          <fileset dir="${test-src.dir}">
              <include name="**/IntegrationTestSuite.java" />
          </fileset>
       </batchtest>
</junit>

build.gradle

task integrationTestSandro(type: Test) {
    reports.html.enabled = false
    include '**/IntegrationTestSuite*'
    reports.junitXml.destination = "$buildDir/test-results/integration"
    maxHeapSize = testTaskMaxHeapSize
    jvmArgs testTaskJVMArgs
}

推荐答案

您应该能够使用Ant任务 JUnitReport 来实现您的目标.像下面这样的东西应该起作用:

You should be able to use the Ant task JUnitReport to achieve your goal. Something like the following should work:

configurations {
    antJUnit
}

dependencies {
    antJUnit 'org.apache.ant:ant-junit:1.9.7'
}

task mergeJUnitReports {
    ext {
        resultsDir = file("$buildDir/allreports")
        targetDir = file("$buildDir/test-results/merged")
    }

    doLast {
        ant.taskdef(name: 'junitreport',
                    classname: 'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator',
                    classpath: configurations.antJUnit.asPath)

        ant.junitreport(todir: resultsDir) {
            fileset(dir: resultsDir, includes: 'TEST-*.xml')
            report(todir: targetDir, format: 'frames')
        }
    }
}

请记住,您将必须声明一个存储库以允许Gradle解析 ant-junit 依赖项.

Keep in mind that you will have to declare a repository to allow Gradle to resolve the ant-junit dependency.

这篇关于Gradle合并Junit报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆