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