我正在使用Junit和Ant来生成一个测试报告,这是默认的junit-noframe格式。由于我在同一个包中测试了几个不同的类,因此我希望看到每个类的测试结果的统计信息。此外,我想在报告中区分成功的测试。
我已经检查了xslt文件,这可能部分解决了第一个问题。在Junit生成的xml测试报告中,成功的案例已经被重新分组。我该如何影响这一点呢?有没有可能改变Junit在xml testResult中存储信息的方式?这些关于单个测试的数据一定在某个地方,因为我可以通过Eclipse中的Junit插件清楚地看到它们。
发布于 2020-04-23 13:33:45
您可以修改xsl文件,为每一行添加类名。这对我很管用。
在junit-noframes.xsl中,在此处添加2行:1:
...
<!-- method header -->
<xsl:template name="testcase.test.header">
<tr valign="top">
<!-- ### THIS LINE ADDED ### -->
<th>Class</th>
<!----------------------------->
<th>Name</th>
<th>Status</th>
<th width="80%">Type</th>
<th nowrap="nowrap">Time(s)</th>
</tr>
</xsl:template>
...还有这里:
...
<xsl:template match="testcase" mode="print.test">
<tr valign="top">
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="failure | error">Error</xsl:when>
</xsl:choose>
</xsl:attribute>
<!-- ### THIS LINE ADDED ### -->
<td><xsl:value-of select="@classname"/></td>
<!----------------------------->
<td><xsl:value-of select="@name"/></td>
<xsl:choose>
<xsl:when test="failure">
<td>Failure</td>
<td><xsl:apply-templates select="failure"/></td>
</xsl:when>
....记住,通过设置"styledir“属性(在build.xml文件中),指定修改后的junit-noframes.xsl文件所在的文件夹。
...
<report todir="${build.test.resultshtml.dir}"
format="noframes"
styledir="${build.resources.dir}"
/>
...新列将在报告中显示类名称
https://stackoverflow.com/questions/16217754
复制相似问题