I summarized the procedure to execute JUnit test in Maven and output the test report (HTML).
<project ...>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</build>
...
</project>
The maven-surefire-plugin configuration is required to avoid problems.
Reference: https://qiita.com/watanabk/items/16e19e30659d0acca519
There is no problem even if you do not list other plugins. (If not stated, the latest version will be used.)
mvn clean \
test -Dmaven.test.failure.ignore=true \
site -DgenerateReports=false \
surefire-report:report
The test is run and the test result report is output to target / site / surefire-report.html
.
The role of each phase or goal is as follows.
clean (Phase)
Delete the build result (target).
test (Phase)
Run the test. Specify -Dmaven.test.failure.ignore = true
to output the report even if there is a failed test.
site (Phase)
Originally a build life cycle for outputting the project site. Since the image and CSS linked to the report are not output only by executing surefire-report: report
, execute by specifying -DgenerateReports = false
and output only the image and CSS.
Reference: https://stackoverflow.com/questions/21432663/how-to-get-the-icons-for-the-resulted-maven-surefire-report-plugin
surefire-report:report (Goal)
Output a report (HTML) from the JUnit execution result (XML) in target / surefire-report
.
Reference: https://maven.apache.org/surefire/maven-surefire-report-plugin/usage.html
Reference: http://maven.apache.org/surefire/maven-surefire-report-plugin/faq.
Recommended Posts