Ant JUnit没有显示失败的测试详细信息

时间:2017-03-15 09:41:50

标签: junit ant ant-junit

我正在使用Ant版本1.9.7和JUnit 4.12。我的build.xml看起来像这样:

<target name="run-junit" depends="init, compile, compile-junit">
    <junit printsummary="yes" >
        <formatter type="xml"/>
        <classpath><pathelement location="lib/junit-4.12.jar"/></classpath>
        <batchtest fork="yes" todir="${out.dir}">
            <fileset dir="${bin.dir}">
                <include name="**/*Test.class"/>
            </fileset>
        </batchtest>
    </junit>
</target>

在控制台中运行ant run-junit时,它只会给我:

[junit] Running at.abc.def.ghi.ABCTest
[junit] Tests run: 5, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.065 sec
Test at.abc.def.ghi.ABCTest FAILED

但没有更多细节。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

要获取有关每项失败测试的详细信息,请使用<formatter type="plain" usefile="false"/>代替<formatter type="xml"/>

<junit printsummary="yes">
    <formatter type="plain" usefile="false"/>
    <classpath><pathelement location="lib/junit-4.12.jar"/></classpath>
    <batchtest fork="yes" todir="${out.dir}">
        <fileset dir="${bin.dir}">
            <include name="**/*Test.class"/>
        </fileset>
    </batchtest>
</junit>

使用“普通”格式化程序提供类似于以下内容的输出:

[junit] Running TestMyTest1
[junit] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.014 sec
[junit]
[junit] Testcase: testMyTest took 0.003 sec
[junit]     FAILED
[junit] expected:<firefox> but was:<null>
[junit] junit.framework.AssertionFailedError: expected:<firefox> but was:<null>
[junit]     at TestMyTest1.testMyTest(TestMyTest1.java:17)
[junit]
[junit] Test TestMyTest1 FAILED