我使用JunitReport任务以HTML格式使用maven生成junit报告。
我在pom.xml中添加了以下项以生成HTML测试报告
<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>html报表名始终显示为junit-noframes.html.。因为我生成了更多的html报告,所以每个html报告都是以与junit-noframes.html.相同的名称生成的。我想给出自定义的html报告名。
如何更改html报表名称?我找不到任何选择。
发布于 2015-09-03 13:01:18
The 文件上说
noframes格式不使用重定向,而是生成一个名为junit-noframes.html的文件。
也不能绕开这条路。但是,您可以像使用ANT一样使用参数,所以下面的内容可以工作:
<report format="noframes" todir="${report.location}" /> 有来自命令行的设置参数的几种方法、一个环境变量或一个build.properties文件。
在我看来,这个元素不允许您更改XSLT转换的输出文件名,但是,如果可以编写自定义XSLT样式表并使用扩展函数,或者可以将ANT配置为使用XSLT2.0处理器并使用xsl:result-document,则可以强制使用输出文件名。不过,要解决这个问题似乎很麻烦。
如果在您的情况下将它们放在不同的目录中就足够了,那么这是一个简单的解决方法。
另一个解决方案根据Suntaragali Qa的提议,您可以通过将文件移动到一个带有时间戳的新名称来解决它。
添加以下内容:
<tstamp>
<format property="timestamp" pattern="yyyyMMddHHmmss" />
</tstamp>并改变这一点:
<junitreport todir="target/surefire-reports">
<fileset dir="target/surefire-reports">
<include name="**/*.xml" />
</fileset>
<report
format="noframes"
todir="target/surefire-reports/html"
styledir="target/surefire-reports" />
</junitreport>
<move
file="target/surefire-reports/html/junit-noframes.html"
tofile="target/surefire-reports/html/junit-report-${timestamp}.html" />我认为第二个解决方案更容易实现,并且使用标准的ANT语法。有关如何执行此操作的更多信息,请参见链接。
https://stackoverflow.com/questions/32324307
复制相似问题