不显示antunit测试中的Echo

时间:2017-12-17 13:29:44

标签: java ant

我有一个蚂蚁项目,我在其中添加了antunit测试。这是执行测试的目标。

<target name="test-build" depends="init-build">
    <au:antunit>
        <fileset file="test.xml"/>
        <au:plainlistener/>
        <au:xmllistener todir="${reports.antunit.dir}"/>
    </au:antunit>
</target>

test.xml看起来像这样

<project xmlns:au="antlib:org.apache.ant.antunit">
    <include file="build.xml" as="main"/>

    <target name="tearDown" depends="main.clean"/>

    <target name="test-project-name">
        <echo>project name is ${ant.project.name}</echo>
        <au:assertTrue>
            <equals arg1="${ant.project.name}" arg2="gradle-to-ant"/>
        </au:assertTrue>
    </target>
</project>

当我运行ant test-build时,echo语句不会打印到控制台或报告中。

test-build:
[au:antunit] Build File: /etc/user/john/projects/gradle-to-ant/test.xml
[au:antunit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.033 sec
[au:antunit] Target: test-project-name took 0.012 sec

BUILD SUCCESSFUL
Total time: 0 seconds

我在其他项目中看到了回声,例如props。如何在反蚂蚁测试中得到回应呢?

1 个答案:

答案 0 :(得分:2)

The output of your echo task is captured so you could use assertions on it (i.e. assertLogContains). In props it looks as if the echos are there for the case when you run the targets manually outside of antunit.

If you want to see echo's output you need to add the logforwarder testlistener to your antunit task, i.e.

<au:antunit>
    <fileset file="test.xml"/>
    <au:plainlistener/>
    <au:xmllistener todir="${reports.antunit.dir}"/>
    <au:logforwarder/>
</au:antunit>