3

我正在尝试将 Ant 脚本添加到我公司的项目中以运行 jUnit 测试。这是我所拥有的:

<target name="unit-tests">
    <junit>
        <classpath>
            <pathelement location="${project.libext.dir}/junit-4.1.jar"/>
        </classpath>
        <batchtest>
            <fileset dir="${project.src-test.dir}/my/company/." />
        </batchtest>
    </junit>
</target>

该脚本正确地抓取了我的 jUnit 测试,但它说有错误。但是所有的输出都会说是这样的:

[junit] Test package.MyTest FAILED

我想知道为什么它失败了。我尝试将一堆属性添加到junit标签(printsummaryshowoutput等),但似乎找不到正确的组合。我设法得到的最好的是:

[junit] Running package.MyTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec

我真的需要完整的堆栈跟踪等,因为当我通过 Eclipse Run As > Junit Test 时测试运行良好。

有人知道如何打印堆栈跟踪吗?

4

2 回答 2

7

找到了答案。需要添加格式化程序。

<target name="unit-tests">
    <junit>
        <classpath>
            <pathelement location="${project.libext.dir}/junit-4.1.jar"/>
        </classpath>
        <formatter type="plain" usefile="false" />
        <batchtest>
            <fileset dir="${project.src-test.dir}/my/company/." />
        </batchtest>
    </junit>
</target>
于 2012-07-31T18:46:33.050 回答
0

您无法从 Ant 输出 AFAIK 中的测试中打印完整的堆栈跟踪;它嵌入在 JUnit 报告文件中。您可以单独浏览它,或者如果您使用 Jenkins 或 CruiseControl 等持续集成服务器来运行您的构建,您可以设置一个链接到测试报告的插件。

于 2012-07-31T18:10:43.110 回答