Context
I use ant1-9-0.jar , ant-junit-1.9.0.jar and ant-launcher-1.9.0.jar to run JUnit programs,
In my code, I have this function that returns a JUnit Task :
public JUnitTask generateRunTestsTask() throws Exception { JUnitTask task = new JUnitTask(); task.init(); JUnitTask.SummaryAttribute sa = new JUnitTask.SummaryAttribute(); sa.setValue("withOutAndErr"); task.setPrintsummary(sa); task.setFork(true); task.setDir(new File(this.deliveryBinDir)); task.createJvmarg().setValue("-Duser.dir=" + this.deliveryBinDir); FormatterElement.TypeAttribute typeFile = new FormatterElement.TypeAttribute(); typeFile.setValue("xml"); FormatterElement formatToFile = new FormatterElement(); formatToFile.setType(typeFile); task.addFormatter(formatToFile); task.setHaltonfailure(false); task.setShowOutput(true); task.setOutputToFormatters(true); List<String> testSuites = getTestJarList(this.deliveryLibFolder); for (String singleSuite : testSuites) { JUnitTest test = new JUnitTest(singleSuite); test.setTodir(this.testReportsFolder); task.addTest(test); } return task; }
JUnit tests run without problems, and the output is successfully saved in .xml .
Question
I need to print the output to the console because I need real-time results (not only at the end of the whole process). To do this, I added a second FormatterElement just below the /** Output to file */ block:
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);
But my console still does not display logs. I also tried removing formatToFile FormatterElement without success. Do you have any suggestions?
Notes:
- these unit tests really have to be forked, they cannot be changed,
- just let me know if you need more code, for example, Ant project settings or Ant purpose ,
- unit tests do contain
Sysouts , - I reproduced the serial
build.xml file that works, - here is the Apache Ant JUnit repository, if necessary.
java junit ant
Stéphane bruckert
source share