Note that there are some explanatory texts on larger screens.

plurals
  1. POJUnit Ant task won't output to screen
    primarykey
    data
    text
    <h3>Context</h3> <p>I am using <a href="http://api.dpml.net/ant/1.7.0/"><code>ant1-9-0.jar</code></a>, <a href="http://www.docjar.com/docs/api/org/apache/tools/ant/taskdefs/optional/junit/package-index.html"><code>ant-junit-1.9.0.jar</code></a> and <code>ant-launcher-1.9.0.jar</code> to run JUnit tests programmatically. </p> <p>In my code, I have this function that returns the <a href="http://javadoc.haefelinger.it/org.apache.ant/1.7.1/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.html">JUnit Task</a>:</p> <pre><code>/** * Generates a JUnit task which runs every single test in a new JVM * @return task The JUnit task * @throws Exception */ public JUnitTask generateRunTestsTask() throws Exception { /* New JUnit task */ JUnitTask task = new JUnitTask(); task.init(); /* Summary settings */ JUnitTask.SummaryAttribute sa = new JUnitTask.SummaryAttribute(); sa.setValue("withOutAndErr"); task.setPrintsummary(sa); /* JVM configuration */ task.setFork(true); task.setDir(new File(this.deliveryBinDir)); task.createJvmarg().setValue("-Duser.dir=" + this.deliveryBinDir); /* Output to file */ FormatterElement.TypeAttribute typeFile = new FormatterElement.TypeAttribute(); typeFile.setValue("xml"); FormatterElement formatToFile = new FormatterElement(); formatToFile.setType(typeFile); task.addFormatter(formatToFile); /* Task options */ task.setHaltonfailure(false); task.setShowOutput(true); task.setOutputToFormatters(true); List&lt;String&gt; testSuites = getTestJarList(this.deliveryLibFolder); for (String singleSuite : testSuites) { JUnitTest test = new JUnitTest(singleSuite); /* Sets reports location */ test.setTodir(this.testReportsFolder); task.addTest(test); } return task; } </code></pre> <p>The JUnit tests run without problem and the output is successfully stored into <code>.xml</code> files.</p> <h3>Issue</h3> <p>I need to print the output to the console, because I want results in live (not only at the end of the whole process). To do so, I have added a second <a href="http://sepp.oetiker.ch/ant-1.6.5-rp/manual/api/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.html"><code>FormatterElement</code></a> just below the <code>/** Output to file */</code> block:</p> <pre><code>/* Output to screen */ FormatterElement.TypeAttribute typeScreen = new FormatterElement.TypeAttribute(); typeScreen.setValue("plain"); FormatterElement formatToScreen = new FormatterElement(); formatToScreen.setType(typeScreen); formatToScreen.setUseFile(false); formatToScreen.setOutput(System.out); task.addFormatter(formatToScreen); </code></pre> <p>But my console still doesn't display the logs. I have also tried to remove the <code>formatToFile</code> <code>FormatterElement</code>, without success. Do you have any suggestions?</p> <h3>Notes:</h3> <ul> <li>these unit tests really need to be forked, it can't be changed,</li> <li>just let me know if you need more code, for example the settings of the <a href="http://api.dpml.net/ant/1.7.0/org/apache/tools/ant/Project.html">Ant Project</a> or the <a href="http://javadoc.haefelinger.it/org.apache.ant/1.7.1/org/apache/tools/ant/Target.html">Ant Target</a>,</li> <li>unit tests indeed contain <code>Sysouts</code>,</li> <li>I've reproduced a consistent <code>build.xml</code> file which works,</li> <li><a href="http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit">here</a> is the Apache Ant JUnit repository if needed.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload