ant junit任务的选项,可以即时转储控制台输出

Gui*_*ume 7 ant junit log4j

使用Ant junit任务启动非回归测试时出现问题:控制台输出仅在测试结束时被转储.当进程Xmx的日志太多时,它会导致一些OOM,这意味着如果进程在结束之前死亡(或被监视程序杀死),则日志将丢失.

<junit fork="true" forkmode="once" timeout="1200000" haltonfailure="no" 
 outputtoformatters="yes" failureProperty="test.failure" dir="${project.test.dir}">
  <junit-opts/>
  <formatter type="xml" />
  <formatter type="brief" />
  <test name="${project.test.suite}" todir="${report.junit.dir}" outfile="@{project.test.name}" />
</junit>
Run Code Online (Sandbox Code Playgroud)

当然,可以通过将日志转储到文件中来解决这个问题(我们使用log4j作为日志API).但是,我们非常希望测试应用程序的控制台输出日志.

是否有设置允许告诉ant junit任务在运行中将控制台输出转储到文件中而不是等待测试套件结束?

谢谢!

voj*_*oji 13

添加showoutput="true"参数到junit命令:

<junit fork="true" showoutput="true" forkmode="once" timeout="1200000" haltonfailure="no" 
 outputtoformatters="yes" failureProperty="test.failure" dir="${project.test.dir}">
  <junit-opts/>
  <test name="${project.test.suite}" todir="${report.junit.dir}" outfile="@{project.test.name}" />
</junit>
Run Code Online (Sandbox Code Playgroud)

避免使用showoutput="true"和格式化程序.这是有问题的,因为它意味着测试stdout和stderr 在输出窗口中出现两次(在运行时,因为showoutput标志,并且在执行之后,因为格式化程序).