【问题标题】:How to aggregate junit test suite results into a single report run by gradle?如何将junit测试套件结果汇总到gradle运行的单个报告中?
【发布时间】:2016-11-14 21:28:54
【问题描述】:

我有一个运行 4 个测试类的 junit 测试套件。当我使用 gradle 运行测试套件时,它会创建 4 个 html 报告,套件中的每个测试类 1 个。我是 gradle 新手,有没有办法让 gradle 将结果合并到一个 html 报告中?

这是我的测试套件。

@RunWith(Suite.class)
@Suite.SuiteClasses([
    TestClass1.class,
    TestClass2.class,
    TestClass3.class,
    TestClass4.class,
])

class MyTestSuite {
}

在我的 gradle.build 文件中,我使用以下测试方法。

test {
  include("com/geb/tests/MyTestSuite.class")
  jvmArgs '-Dsomevariabe=someValue'
}

我使用 gradle 命令运行我的测试套件:gradle :web-tests:test

然后,当测试套件完成运行时,会为每个类创建 4 个 html 文件。保存在web-tests\build\reports\tests\classes

testClass1.html
testClass2.html
testClass3.html
testClass4.html

每个 testClass.html 文件列出了每个测试用例的通过或失败状态。

我想要一个包含所有测试用例通过或失败状态的组合列表的 html 文件。这可能吗?

【问题讨论】:

    标签: gradle junit build.gradle


    【解决方案1】:

    This plugin 可以帮助你。将此添加到您的build.gradle:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.kncept.junit.reporter:junit-reporter:2.1.0'
        }
    }
    plugins {
        id 'com.kncept.junit.reporter' version '2.1.0'
    }
    
    apply plugin: 'com.kncept.junit.reporter'
    
    junitHtmlReport {
        // The maximum depth to traverse from the results dir.
        // Any eligible reports will be included
        maxDepth = 5
        
        // Directory where to search (exact or relative to build path)
        testResultsDir = '/path/to/root/of/project'
        // Where to output 
        testReportsDir = 'reports/junit'
        
        // Fail build when no XML files to process
        failOnEmpty = true
    }
    

    现在构建报告: ./gradlew junitHtmlReport

    为找到的所有 JUnit XML 文件创建一个 HTML 报告到./reports/junit。请注意,这会组合 TEST-*.xml 之类的文件,而不是 html 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-31
      • 2016-11-29
      • 1970-01-01
      • 1970-01-01
      • 2013-02-02
      • 2013-05-07
      相关资源
      最近更新 更多