46

このsurefire-reportプラグインは、自分の作業スタイルには非常に適していません。私は常にプロジェクトをクリーンアップしており、ブラウザーでテスト レポートを確認するたびにサイト全体を再構築するのに 5 分も費やしたくありません。

と入力mvn surefire-report:report-onlyすると、生成されたレポートは見苦しく、ほとんど読めません。

私が探しているのは、ant の JUnitReport タスクのようなものです。すでに入手可能なものはありますか?

4

8 に答える 8

81

これが私がすることです:

# 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 秒で実行されました。

それが役立つことを願っています。楽しみ!

于 2014-05-30T16:07:06.350 に答える
31
于 2010-05-17T08:10:55.273 に答える
4

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 を使用しており、何よりも優れています。ただし、テストが失敗したときにテスト レポートを生成する方法はまだ見つかりません。どうすればいいですか?

于 2010-05-19T09:10:13.943 に答える
4

新しいmaven実行構成を作成し、目標を指定して=>

surefire-report:report site -DgenerateReports=false

これにより、css を使用したレポート ビューが向上します。

于 2016-07-06T12:33:43.260 に答える
3

-Dmaven.test.failure.ignore=trueテストが失敗したときにテスト レポートを生成するように設定できます。

于 2010-06-25T19:13:07.450 に答える
2

目標サイト 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>
于 2013-08-21T22:40:21.800 に答える
0

上記のようにこの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>
于 2020-05-07T07:51:15.507 に答える