tags:

views:

104

answers:

2

We're using the task within our master build to invoke targets in separate ant builds for each of our sub-projects. So far so good, we get things built, we can even run JUnit tasks within each one and everybody is happy. However...

We want to take it to the next level, we would like to have a single JUnit report generated from the JUnit test result XML for all of our sub-projects but if we terminate the build whenever any of the sub-projects has a unit test failure, we never get to the point where we can generate a unified report. So that suggests that we would somehow note that unit tests failed within one or more of the sub-projects and not fail immediately but wait until the end of the master build to fail.

What mechanism exists for that communication from the child builds up to the master build though? Properties are immutable and everything else we think of (properties files we update, files we touch, etc.) seem like horrible kludges. Is there a way to do this that fits in nicely with Ant and doesn't seem like something horrible we grafted on?

A: 

The junit task supports the haltonerror and haltonfailure attributes, which, if set to false, will cause the ant script to continue to run even if a test fails. There is also an errorproperty and failureproperty you can set instead. You can then copy your junit reports to a master directory (with all success and failures), and use the fail task to fail if either of those properties have been set.

Something along the lines of:

<target name="run-tests" >
    <junit printsummary="on" fork="yes" haltonfailure="false" haltonerror="false" errorproperty="test.failed" failureproperty="tests.failed" showoutput="true" maxmemory="512m">
  <classpath refid="classpath" />
  <formatter type="xml" />
  <batchtest todir="test/reports">
   <fileset dir="${build.classes.dir}">
    <patternset refid="testfiles" />
   </fileset>
  </batchtest>
 </junit>
    <copy todir="test/master/reports" dir="test/reports" />
 <fail if="tests.failed"/>
</target>
jordan002
Sorry... having major issues with the SO XML formatter
jordan002
A: 

OK, I never got an answer on this one that I liked that much but we did end up finding a good solution we like a lot. We switched from using Anthill OS as our build server to Hudson and after we did that we were able to take advantage of a Hudson feature where it will aggregate JUnit results from any number of locations to produce a single report that goes with each build (whether successful or not). So, in short, use Hudson. It rocks!

John Munsch