0

I'm using Junit with Ant to generate a test report the default junit-noframes format. Since I'm testing several different classes in the same package I'd like to see the statistics on the test results for each class. In addition, I'd like to separate the successfull tests in the report.

I've already examinated the xslt file, that may allows me to partially solve the first problem. Still in the xml test report generated by Junit the successfull cases are already regrouped. How can I affect this? Is it possible to change the way Junit stocks the informations in the xml testResult? These datas concerning the individual tests must be somewhere, since I'm clearly able to see them with the Junit plugin in Eclipse.

4

1 回答 1

0

您可以修改 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}"
        />
...

新列将在报告中显示班级名称

点击查看图片...

于 2020-04-23T05:33:45.263 回答