maven-antrun-plugin可以生成显示异常错误的HTML报告吗?

时间:2013-08-21 19:09:02

标签: maven surefire maven-antrun-plugin

我有一个Maven Surefire报告,可生成3个文件:

   TESTS-TestSuites.xml  - shows only passing tests. no info about fails or errors.
   TEST-me.qa.MyTest.xml - see below
   me.qa.MyTest.txt - file containing console output showing exceptions

每次失败的测试都会在 TEST-me.qa.MyTest.xml 文件中显示错误,如下所示:

<testcase name="testIPcheckCanCalculate" classname="me.qa.TestLogChecks" time="0.016">
    <failure message="Average is too low: 0.5357142857142857. Min: 20.0" 
       type="java.lang.AssertionError">java.lang.AssertionError: Average is too low:
         0.5357142857142857. Min: 20.0
    at org.junit.Assert.fail(Assert.java:88)
    at org.junit.Assert.assertTrue(Assert.java:41)
    at me.qa.TestLogChecks.testIPcheckCanCalculate(TestLogChecks.java:230)
</failure>
    <system-out>Testing InPreparer.getInv().getSomething().checkCanCalculate() ...
</system-out>
  </testcase>

maven-antrun-plugin能否生成显示异常错误(并失败)的HTML报告?目前,名为junit-noframes.html的JUNit输出文件仅显示 TESTS-TestSuites.xml 中的信息,因此根本没有显示任何失败信息(即使我的include是*。 XML)。我的解决方法是查看 me.qa.MyTest.txt 文件以查看错误是什么,但我希望这些错误出现在我的报告中,并且还显示失败的测试总数报告。

这是我的Maven配置:

<plugin>
    <artifactId>maven-antrun-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="frames" todir="target/surefire-reports" />
                    </junitreport>
        </tasks>
        </configuration>
    <goals>
        <goal>run</goal>
        </goals>
    </execution>
</executions>
<dependencies>
    <dependency>
        <groupId>ant</groupId>
    <artifactId>ant-junit</artifactId>
    <version>1.6.5</version>
    </dependency>
        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-trax</artifactId>
            <version>1.8.0</version>
        </dependency>
</dependencies>
</plugin>

或者,我这样做是错的,Surefire本身可以生成合适的报告吗?

1 个答案:

答案 0 :(得分:0)

我解决了。我现在使用maven-surefire-report插件以及目标 site maven-surefire:report ,而不是使用maven-antrun-plugin。注意:您需要先运行站点目标才能生成报告的CSS文件。

    <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>2.1</version>
                <configuration>
                    <outputDirectory>${basedir}/target/surefire-reports</outputDirectory>
                </configuration>
            </plugin>
        </plugins>
    </reporting>

</project>