Generate HTML format test report with plugin Maven-surefire-report-plugin

Source: Internet
Author: User

By default, the Maven test/maven package/maven Install command generates output information in TXT and XML format in the Target/surefire-reports directory.

In fact, Maven can also generate a report in HTML format, just need to use a plugin: Maven-surefire-report-plugin.

Features of this plugin:

1. Ability to convert generated XML reports to HTML

2. Can specify which test classes need to be executed, which test classes are not executed

3. Can be compatible with JUnit 3, JUnit 4 and testng

4. By default, we cannot invoke it in a certain life cycle, because not all users will need HTML formatting each time they build the software.

If you want to generate a test report in HTML format, we need to execute the command separately: MVN surefire-report:report

The steps that are performed to invoke this command:

1. Compile the source files and test cases first

2. Call the Surefire plugin (the plug-in is primarily used to perform unit tests) to generate the test output information for the number of TXT and XML

The 3.surefire report plugin (aka Maven-surefire-report-plugin) translates all XML reports under Target/surefire-reports into a single copy of the HTML-formatted files. and save this HTML-formatted test report in the Target/site directory.

Example:

1. Create the project Mavenreport. Contains the class Try2 and the test class three, respectively: Junittest.java,testcase2.java and Trytest.java

2. Add plugin maven-surefire-report-plugin to the pom file and specify which class test classes need to be executed and which test classes do not need to be executed.

<include>**/*Test.java</include>: Represents all Java classes under any subdirectory named End with Test.

<exclude> **/test*.java </exclude>: Indicates that all Java classes named start with Test are not executed under any subdirectories.

3. Execute mvn surefire-report:report command

4. Results:

Generate 2 XML files and two txt files in the Surefire-reports directory: (careful you should find the name of the test class in the XML file name, and only the test class junittest,trytest is executed.) TestCase2 not executed)

Generates an HTML file under the site directory.

Open surefire-report.html File:

Generate HTML Format test report with plug-in maven-surefire-report-plugin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.