JUnit&Ant:如何在屏幕上显示详细的错误消息?

Kev*_*vin 5 java ant junit

我建立了一个Ant项目,其中包括使用JUnit的单元测试.

测试目标如下:

<target name="test">
    <mkdir dir="target/test/reports"/>
    <junit printsummary="yes" haltonfailure="yes">
        <classpath>
            <pathelement location="${test.classes.dir}"/>
            <pathelement location="${test.junit.jar}" />
            <pathelement path="${classes.dir}"/>
            <pathelement path="${java.class.path}"/>
        </classpath>
        <formatter type="plain"/>

        <batchtest fork="yes" todir="${test.reports.dir}">
            <fileset dir="${test.src.dir}">
                <include name="**/*Test*.java"/>
            </fileset>
        </batchtest>
    </junit>
</target>
Run Code Online (Sandbox Code Playgroud)

当我运行此测试时,它只在屏幕上显示测试的摘要,如:

Buildfile: F:\test\build.xml

test:
    [junit] Running com.mycompany.myproject.myTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.013 sec
    [junit] Running com.mycompany.myproject.myTest1
    [junit] Tests run: 3, Failures: 1, Errors: 0, Time elapsed: 0.018 sec

BUILD FAILED
F:\test\build.xml:30: Test com.mycompany.myproject.myTest1 failed

Total time: 1 second
Run Code Online (Sandbox Code Playgroud)

无论如何,我可以告诉JUnit或Ant在屏幕上显示详细结果吗?

另外,如果我想在单元测试中写一些东西到屏幕上,我该怎么办呢?我试图在测试中插入System.out.println()但它不会在屏幕上显示任何内容.

非常感谢.

Dav*_*ton 3

将showOutput标志设置为 true。

您想在测试过程中通过 Sop 实现什么目标?