未显示在抗单元测试中的回声



我有一个蚂蚁项目,我在其中添加了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

我已经看到在其他项目(例如道具)中使用的Echo。我如何让Echo进行抗单元测试?

捕获echo任务的输出,因此您可以在其上使用断言(即assertLogContains)。在道具中,当您手动在Antunit外手动运行目标时,echo s似乎在那里。

如果您想查看echo的输出,则需要将logforwarder TestListener添加到antunit任务,即。

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

最新更新