option for ant junit task to dump console output o

2019-04-26 18:44发布

问题:

I have an issue when using the Ant junit task to launch my non-regression tests: the console output is only dumped when the test end. It causes some OOM when there are too many logs with respect to the process Xmx and means that if the process dies (or is killed by a watchdog) before its end the logs are lost.

<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>

The issue could be worked around by dumping the logs in a file (we use log4j as a logging API), certainly. However we would very much like to test the console output logs of the application.

Is there a setting permitting to tell the ant junit task to dump the console output in a file on-the-fly and not to wait for the test suite to end?

Thanks!

回答1:

Add showoutput="true" parameter, to junit command:

<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>

Avoid using showoutput="true" and formatters. It is problematic, because it means that test stdout & stderr appears twice in the Output Window (in runtime, because showoutput flag, and after execution, because formatters).



标签: ant junit log4j