【问题标题】:JUnit report not showing all classes tested when using Categories and ANTJUnit 报告未显示使用类别和 ANT 时测试的所有类
【发布时间】:2012-12-18 09:18:53
【问题描述】:

使用 ANT 脚本运行 JUnit 测试,一组测试 (TestSCF) 是所有测试的子集。这些测试将作为夜间构建的一部分运行并生成报告。使用@IncludeCategory 定义需要运行的测试,使用ClasspathSuite 定位项目中的所有测试。

一个示例测试类声明,定义为作为 T​​estSCF 子集运行。 TestSCF 是一个空接口。

@Category(TestSCF.class)
public class ErrorDialogTest extends TestCase
{
    ....
}

主要的测试套件。

@RunWith(Categories.class)
@IncludeCategory(TestSCF.class)
@SuiteClasses({AllTests.class})
public class SCFTests
{
}

AllTests 声明

@RunWith(ClasspathSuite.class)
public class AllTests
{
}

ANT脚本的相关部分

<!-- Run the unit tests -->
<junit showoutput   ="true"
       printsummary = "yes"
       fork         = "yes"
       timeout      = "60000" >
  <formatter type="xml"/>
  <classpath refid="cpath"/>

  <batchtest fork  = "yes"
             todir = "${test.report.dir}">
    <fileset dir="${src.dir}">
      <include name="**/SCFTests.java"/>
    </fileset>
  </batchtest>
</junit>

<!-- Copy the XML files that get deleted by junitreport -->
<mkdir dir="${junit.html.dir}/xml_files"/>
<copy todir="${junit.html.dir}/xml_files" preservelastmodified="true">
  <fileset dir="${test.report.dir}">
      <include name="*.xml"/>
  </fileset>
</copy>

<!-- Format the test results into browsable HTML -->
<junitreport todir="${junit.html.dir}">
  <fileset dir="${test.report.dir}">
    <include name="TEST-*.xml"/>
  </fileset>
  <report format="frames" todir="${junit.html.dir}"/>
</junitreport>

问题在于 Junit 报告只显示了一个经过测试的类 - SCFTests。我理解为什么会发生这种情况,但想知道是否有一种方法可以为每个实际测试的类生成报告,或者有一种方法可以将测试的类的名称添加到测试结果的“名称”中报告。

例如:

dev.sca.test.ErrorDialogTest 45 Passed, 3 Failures, 0 Errors

相对

SCFTests 45 Passed, 3 Failures, 0 Errors

【问题讨论】:

    标签: java ant junit


    【解决方案1】:

    为了将来参考,我可以通过如下修改 junit-frames.xsl 文件来获得打印在报告的“名称”列中的类路径。

    <td>
      <a name="{@name}"/>
      <xsl:choose>
        <xsl:when test="boolean($show.class)">
          <a href="{concat($class.href, '#', @name)}"><xsl:value-of select="@name"/></a>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@name"/>
        </xsl:otherwise>
      </xsl:choose>
    </td>
    

    变成

    <td>
      <a name="{@name}"/>
      <xsl:choose>
        <xsl:when test="boolean($show.class)">
          <a href="{concat($class.href, '#', @classname)}"><xsl:value-of select="@classname"/></a>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@classname"/>
        </xsl:otherwise>
      </xsl:choose>
    </td>
    

    结果:

    Name                         Status Type    Time(s)
    dev.sca.test.ErrorDialogTest Success        1.45
    dev.sca.test.SomeOtherTest   Success        2.03
    

    【讨论】:

    • junit-frames.xsl 文件在哪里以及在哪里进行更改以使用修改后的框架 xsl?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2023-03-24
    相关资源
    最近更新 更多