Mavenで単体テスト結果をレポート出力してみました。その時の設定メモを残したいと思います。
Gradleの場合と同様にプラグインを入れて出力しています。(Gradleの場合はapply plugin: 'java')
※あくまでメモなのでそのままでは実行できない可能性が高いです。
使用するプラグイン
- maven-surefire-report-plugin
- maven-site-plugin
maven-surefire-report-pluginだけでも出力はできますが、CSSなどが出力されません(チェックマークも表示されない)。
そのため、maven-site-pluginで作成できるプロジェクトサイトに使われるCSSを使うことにします。
設定
pom.xmlにプラグインの設定を追加します。(...は省略)
<?xml version="1.0" encoding="UTF-8"?>
<project>
...
<build>
...
<plugins>
...
<!-- report -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.0</version>
</plugin>
</plugins>
</build>
...
</project>
レポート出力
pom.xmlが存在するフォルダで、
以下のコマンドを実行してレポート出力します。
$ mvn clean # 実行しない場合、前回の結果が混ざってしまう
$ mvn site:site -DskipTests
$ mvn -Dtest=**/sample/*Test surefire-report:report
参考
https://maven.apache.org/surefire/maven-surefire-plugin/index.html
https://maven.apache.org/surefire/maven-surefire-report-plugin/index.html
https://maven.apache.org/plugins/maven-site-plugin/index.html
https://kikutaro777.hatenablog.com/entry/2013/01/13/201253