How to Display jUnit Errors Via Ant

2019-02-24 22:28发布

I am trying to add an Ant script to my company's project to run the jUnit tests. Here is what I have:

<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>

The script is grabbing my jUnit tests correctly, but it's saying there are errors. But all the output will say is things like:

[junit] Test package.MyTest FAILED

I want to know why it failed. I have tried adding a bunch of the attributes to the junit tag (printsummary, showoutput, etc), but can't seem to find the right combination. The best I have managed to get is:

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

I really need the full stack trace, etc as the test runs fine when I Run As > Junit Test via Eclipse.

Anyone know how to make the stack trace print?

标签: ant junit
2条回答
小情绪 Triste *
2楼-- · 2019-02-24 23:04

Found the answer. Needed to add a formatter.

<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>
查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-02-24 23:08

You can't print the full stack trace from the tests in the Ant output AFAIK; it's embedded in the JUnit report file. You can either browse that separately, or if you're using a continuous integration server such as Jenkins or CruiseControl to run your builds, you can set up a plugin that will link to the test reports.

查看更多
登录 后发表回答