我将Junit与Ant结合使用以生成默认junit-noframes格式的测试报告。由于我正在同一包中测试几个不同的类,因此我希望查看每个类的测试结果统计信息。另外,我想将报告中的成功测试分开。
我已经检查过xslt文件,可以让我部分解决第一个问题。仍然在Junit生成的xml测试报告中,成功的案例已经被重新分组。我该如何影响?是否可以更改Junit在xml testResult中存储信息的方式?这些与各个测试有关的数据必须在某个地方,因为我可以通过Eclipse中的Junit插件清楚地看到它们。
您可以修改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}"
/>
...
新列将在报告中显示班级名称