我建立了一个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>

当我运行此测试时,它仅在屏幕上显示测试摘要,例如:
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

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

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

非常感谢。

最佳答案

showOutput标志设置为true。

在测试过程中,您想通过S.o.p完成什么?

10-07 13:10
查看更多