JUnit没有提供有关“错误”的信息。

18

我正在使用Junit 4.4和Ant 1.7。如果测试用例由于错误而失败(例如,因为方法抛出了意外的异常),我将无法获得有关错误的任何详细信息。

我的build.xml文件如下所示:

<target name="test" depends="compile">
<junit printsummary="withOutAndErr" filtertrace="no" fork="yes" haltonfailure="yes" showoutput="yes">
  <classpath refid="project.run.path"/>
  <test name="a.b.c.test.TestThingee1"/>
  <test name="a.b.c.test.NoSuchTest"/>
</junit>
</target>
当我运行“ant test”时,它会显示(例如)2个测试运行,0个失败,1个错误。即使完全合理并且可以让我找出错误的原因,它也不会说“没有名为NoSuchTest的测试”。
谢谢!
-Dan
2个回答

34

明白了 :)

我需要在junit块内添加一个"formatter"。

<formatter type="plain" usefile="false" />

真麻烦。

-丹


7
如果您要进行大量测试,有两个更改可能需要考虑:
  1. 运行所有测试而不是在第一个错误处停止
  2. 创建显示所有测试结果的报告
使用junitreport任务非常容易实现。
<target name="test">
    <mkdir dir="target/test-results"/>
    <junit fork="true" forkmode="perBatch" haltonfailure="false"
           printsummary="true" dir="target" failureproperty="test.failed">
        <classpath>
            <path refid="class.path"/>
            <pathelement location="target/classes"/>
            <pathelement location="target/test-classes"/>
        </classpath>
        <formatter type="brief" usefile="false" />
        <formatter type="xml" />
        <batchtest todir="target/test-results">
            <fileset dir="target/test-classes" includes="**/*Test.class"/>
        </batchtest>
    </junit>

    <mkdir dir="target/test-report"/>
    <junitreport todir="target/test-report">
        <fileset dir="target/test-results">
            <include name="TEST-*.xml"/>
        </fileset>
        <report format="frames" todir="target/test-report"/>
    </junitreport>

    <fail if="test.failed"/>
</target>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接