[Project combat] Introduction to Maven plug-ins related to unit testing - maven-surefire-report-plugin plug-in description

1. Introduction to the maven-surefire-report-plugin plugin

The maven-surefire-report-plugin plugin is a plugin for Maven, which is used to generate unit test reports based on JUnit and TestNG. The plug-in generates a test report in HTML format by parsing the test result file, so as to facilitate the analysis and tracking of test results in the project.

The maven-surefire-report-plugin plugin is a very useful plugin that helps developers better understand unit test coverage and results in their projects. By analyzing test reports, you can discover deficiencies in test cases and further optimize test cases to improve code quality and reliability.

The function of the maven-surefire-report-plugin plug-in is to convert the test report into Html format. For specific parameter settings, you can go to technical related resources to view

2. How to use the maven-surefire-report-plugin plugin

The following are the basic configuration steps for the maven-surefire-report-plugin plugin:

2.1 Add maven-surefire-report-plugin plugin

Add the maven-surefire-report-plugin plugin to the pom.xml file of the project.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-report-plugin</artifactId>
      <version>2.22.2</version>
    </plugin>
  </plugins>
</build>

2.2 Run the Maven command to generate a test report

For example:

mvn site

This will run all tests in the project and generate a test report file at target/site/surefire-report.html.

2.3 Modify the name of the generated report file

The default name is: surefire-report

<outputName>xxx-surefire-report</outputName>

2.4 View test report

Open the target/site/xxx-surefire-report.html file,

It will display unit test results for JUnit and TestNG
, including test case details, number of passed and failed test cases, coverage statistics, etc.
You can also view code coverage for each test case, along with line-of-code coverage statistics.

3. Other settings of the plug-in

3.1 Set the task unit setting phase of the plug-in

test, which means that the maven plugin life cycle is executed in the test phase;

3.2 Set the minimum unit goal for executing tasks

It can be bound to any phase. A phase has one or more goals, and the goals are also executed in order. When a phase is executed, the goals bound to the phase will be executed in order according to the binding time, regardless of How many goals have been bound to the phase, and the goals you define can continue to be bound to the phase. Simple setting example:

<goals>
	<goal>report-only</goal>
	<goal></goal>
</goals>

Guess you like

Origin blog.csdn.net/wstever/article/details/131806272#comments_27991279