JUnit3 and Junit4 XML Reports with Maven

前端 未结 2 1584
旧巷少年郎
旧巷少年郎 2021-01-12 07:36

I am trying to figure out how to use the supposed reporting capabilities of JUnit (3 and 4) in conjunction with Maven, but Google searches aren\'t turning up much in the way

相关标签:
2条回答
  • 2021-01-12 08:01

    The Maven Surefire Plugin is the plugin that runs tests and generates 2 raw reports by default:

    The Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application. It generates reports in 2 different file formats:

    • Plain text files (*.txt)
    • XML files (*.xml)

    By default, these files are generated at ${basedir}/target/surefire-reports

    The plugin has some parameter allowing to tweak the reports a bit. From the surefire:test mojo documentation:

    • disableXmlReport : Flag to disable the generation of report files in xml format. Default value is: false.
    • reportFormat : Selects the formatting for the test report to be generated. Can be set as brief or plain. Default value is: brief.
    • trimStackTrace : Whether to trim the stack trace in the reports to just the lines within the test, or show the full trace. Default value is: true.

    For an HTML format of the report, you can then use the Maven Surefire Report Plugin:

    The Surefire Report Plugin parses the generated TEST-*.xml files under ${basedir}/target/surefire-reports and renders them to DOXIA which creates the web interface version of the test results.

    You can either get the report generated as part of the site generation or by running the standalone surefire-report:report goal. From the Usage page:

    Generate the report as part of Project Reports

    To generate the Surefire report as part of the site generation, add the following in the section of your POM:

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

    When the mvn site is invoked, the report will be automatically included in the Project Reports menu as shown in the figure below.


    (source: apache.org)

    Generate the report as standalone

    The Surefire report can also generate the report using its standalone goal:

    mvn surefire-report:report  
    

    A HTML report should be generated in ${basedir}/target/site/surefire-report.html.


    (source: apache.org)

    0 讨论(0)
  • 2021-01-12 08:07

    The Maven Surefire Plugin is what executes a lot of the test reports.

    You may also want to look at Cobertura for code coverage.

    0 讨论(0)
提交回复
热议问题