【问题标题】:Java test report that includes logs包含日志的 Java 测试报告
【发布时间】:2019-08-17 09:54:19
【问题描述】:

是否有 maven 或 gradle 插件可以生成 html 报告,包括每个测试用例的日志输出(通过或失败)?

我尝试过使用 maven 的surefire,但它似乎没有提供这样的功能。

我有点喜欢你在 intellij 上导出的 html 测试报告。

【问题讨论】:

    标签: java maven gradle junit


    【解决方案1】:

    在 maven 中,您可以像这样通过surefire-report 完成:

    <project>
      ...
      <reporting>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>3.0.0-M3</version>
          </plugin>
        </plugins>
      </reporting>
      ...
    </project>
    

    或者在命令行中:mvn surefire-report:report

    使用 gradle,你可以这样做:

    test {
        reports {
            html.enabled = true
        }               
    }
    

    为 gradle 提供参考:https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:reports

    编辑: 要包含来自 sys.out/sys.err 的日志,请在 pom surefire 插件大括号中执行此操作:

        <configuration>
            <redirectTestOutputToFile>true</redirectTestOutputToFile>
        </configuration>
    

    【讨论】:

    • Surefire 在 html 报告中不包含日志输出。
    • 哦,对不起,我的错,不知道你需要日志,确实如此,编辑了我的答案
    • Gradle 在 html 报告中包含日志输出。我正在寻找使用 maven 的类似解决方案。使用surefire,日志被保存为txt文件,但它们不是html的一部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多