このsurefire-reportプラグインは、自分の作業スタイルには非常に適していません。私は常にプロジェクトをクリーンアップしており、ブラウザーでテスト レポートを確認するたびにサイト全体を再構築するのに 5 分も費やしたくありません。
と入力mvn surefire-report:report-onlyすると、生成されたレポートは見苦しく、ほとんど読めません。
私が探しているのは、ant の JUnitReport タスクのようなものです。すでに入手可能なものはありますか?
これが私がすることです:
# Run tests and generate .xml reports
mvn test
# Convert .xml reports into .html report, but without the CSS or images
mvn surefire-report:report-only
# Put the CSS and images where they need to be without the rest of the
# time-consuming stuff
mvn site -DgenerateReports=false
レポートについては、target/site/surefire-report.html にアクセスしてください。
テストの実行後、残りの 2 つは約 3.5 秒で実行されました。
それが役立つことを願っています。楽しみ!
Pascal に感謝します。やりたいことを実行するための改善されたソリューションを見つけました。
<plugin>
<!-- Extended Maven antrun plugin -->
<!-- https://maven-antrun-extended-plugin.dev.java.net/ -->
<groupId>org.jvnet.maven-antrun-extended-plugin</groupId>
<artifactId>maven-antrun-extended-plugin</artifactId>
<executions>
<execution>
<id>test-reports</id>
<phase>test</phase>
<configuration>
<tasks>
<junitreport todir="target/surefire-reports">
<fileset dir="target/surefire-reports">
<include name="**/*.xml"/>
</fileset>
<report format="noframes" todir="target/surefire-reports"/>
</junitreport>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-junit</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-trax</artifactId>
<version>1.8.0</version>
</dependency>
</dependencies>
</plugin>
このバージョンは、より新しいバージョンの ant を使用しており、何よりも優れています。ただし、テストが失敗したときにテスト レポートを生成する方法はまだ見つかりません。どうすればいいですか?
新しいmaven実行構成を作成し、目標を指定して=>
surefire-report:report site -DgenerateReports=false
これにより、css を使用したレポート ビューが向上します。
-Dmaven.test.failure.ignore=trueテストが失敗したときにテスト レポートを生成するように設定できます。
目標サイト maven-surefire:reportを使用して行った方法は次のとおりです。
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.16</version>
<configuration>
<showSuccess>false</showSuccess>
<outputDirectory>${basedir}/target/surefire-reports</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<configuration>
<outputDirectory>${basedir}/target/surefire-reports</outputDirectory>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
上記のようにこのpomを追加します
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>test-reports</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<tasks>
<junitreport todir="target/surefire-reports">
<fileset dir="target/surefire-reports">
<include name="**/*.xml" />
</fileset>
<report format="noframes" todir="target/surefire-reports" />
</junitreport>
</tasks>
</configuration>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-junit</artifactId>
<version>version</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>version</version>
</plugin>