小智 56
这就是我做的:
# 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
Run Code Online (Sandbox Code Playgroud)
转到target/site/surefire-report.html获取报告.
测试运行后,其余的两个在我的运行时间约为3.5秒.
希望有所帮助.请享用!
Pas*_*ent 27
实际上,在每个构建中生成整个站点显然不是一种选择.但问题是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>
Run Code Online (Sandbox Code Playgroud)
更新:我最初的想法是"按需"运行Maven AntRun插件以生成报告......但这不是我发布的内容,我将其限制在test阶段...但我没有想到失败的情况测试(将停止构建并阻止AntRun插件的执行).那么,要么:
不要将AntRun插件绑定到test阶段,将配置移到外部execution并mvn antrun:run在命令行上调用以在需要时生成报告.
或者使用testFailureIgnore测试mojo 的选项并在surefire插件配置中将其设置为true:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)或使用-D参数从命令行设置此表达式:
$ mvn test -Dmaven.test.failure.ignore=true
Run Code Online (Sandbox Code Playgroud)我认为选项#1是最好的选择,你不一定要生成报告(特别是当测试通过时)并系统地生成它们可能会减慢长期的构建速度.我会"按需"生成它们.
小智 6
创建一个新的 Maven 运行配置并设置 goal =>
surefire-report:report site -DgenerateReports=false
Run Code Online (Sandbox Code Playgroud)
这可以帮助您使用 css 获得更好的报表视图。