我发现surefire-report
插件非常不适合我的工作风格。我一直都在清理这个项目,每次我想在浏览器中查看测试报告时,我都不想花费5分钟来重建整个站点。Maven有没有像样的HTML Junit报告插件?
如果我输入mvn surefire-report:report-only
,生成的报告太丑陋,几乎不可读。
我在找的是类似ant的JUnitReport任务。有没有可用的那里?
我发现surefire-report
插件非常不适合我的工作风格。我一直都在清理这个项目,每次我想在浏览器中查看测试报告时,我都不想花费5分钟来重建整个站点。Maven有没有像样的HTML Junit报告插件?
如果我输入mvn surefire-report:report-only
,生成的报告太丑陋,几乎不可读。
我在找的是类似ant的JUnitReport任务。有没有可用的那里?
事实上,在每个版本生成整个网站显然不是一种选择。但问题是,mvn surefire-report:report-only
不会创建css/*。css文件,因此会导致难看的结果。这是记录在SUREFIRE-616(并不意味着会发生,虽然)。就个人而言,我不使用HTML有报道称,这样我可以忍受的,但是这不是一个很好的答案所以这里是一个基于Ant任务(*叹*)解决方法:
<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="noframes" 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.2</version>
</dependency>
</dependencies>
</plugin>
更新:我最初的想法是“按需”运行Maven AntRun插件生成报告......但这不是我发布的内容,我将它绑定到test
阶段......但我没有考虑失败测试的情况(这会停止构建并阻止AntRun插件的执行)。所以,无论是:
不要绑定AntRun插件的test
阶段,移动execution
外的配置和调用mvn antrun:run
在命令行上以产生想要当的报告。
或使用测试魔力的testFailureIgnore
选项并将其设置为true在万无一失插件配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
或设置使用-D参数从命令行此表达式:
$ mvn test -Dmaven.test.failure.ignore=true
我认为选项#1是最好的选择,你不一定要生成报告(特别是当测试通过)和系统地生成它们可能会减缓建设的长期性。我会按需求生成它们。
感谢帕斯卡,我已经找到了新的改进方案做我想做的事:
<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>
这个版本使用的蚂蚁的新版本以及所有最好的。但是,当测试失败时,我仍然没有找到生成测试报告的方法。我应该怎么做?
您可以设置-Dmaven.test.failure.ignore=true
在测试失败时生成测试报告。
这里是我做到了使用目标网站Maven的万无一失:报告:
<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>
这是我做的:
# 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
去瞄准/网站/报告的surefire-report.html。
经过测试运行后,其余的两个运行约3.5秒对我来说。
希望有所帮助。请享用!
这应该被视为取得成果和答案的最简单方法。 – vikramvi 2016-12-05 10:14:33
创建一个新的Maven运行配置,并与目标=>
surefire-report:report site -DgenerateReports=false
这可以帮助你与CSS更好的报表视图。
运行下面的命令
mvn clean install surefire-report:report
您可以在报告中下方位置
{basedir}/target/site/surefire-report.html
欲了解更多详情,请参阅以下链接
http://maven.apache.org/surefire/maven-surefire-report-plugin/usage.html
是否打开子进程或只运行蚂蚁嵌入?如果这只是嵌入蚂蚁,它的任务,这正是我需要的。 – 2010-05-17 10:05:18
@jimmy它在同一个进程中运行ant任务。 – 2010-05-17 10:59:49
感谢这正是我需要知道的! – 2010-05-19 10:07:02