I would like to set things up via Ant to run my JUnit tests and report on things both at a summary level and an individual class level. I'd like to have all of the tests run, even if there are some errors, but have the overall build fail if there are any errors.
Here's what I currently have in the build.xml file:
<target name = "test" depends="compiletest" description="run unit tests">
<junit haltonfailure="yes">
<classpath path="${buildtest}">
<path refid="test.classpath"/>
</classpath>
<batchtest fork="yes">
<formatter type="brief" usefile="false"/>
<fileset dir="${test}">
<include name="**/*Test.java"/>
<include name="**/Test*.java"/>
</fileset>
</batchtest>
</junit>
</target>
Assuming I have two test classes, each of which has 1 error in it, it would produce the following output:
Buildfile: /opt/project/build/build.xml
init:
compile:
compiletest:
test:
[junit] Testsuite: com.company.foo.TestQuoteParser
[junit] Tests run: 3, Failures: 1, Errors: 0, Time elapsed: 0.013 sec
[junit]
[junit] Testcase: thisShouldThrowException(com.company.foo.TestQuoteParser): FAILED
[junit] Expected exception: java.lang.RuntimeException
[junit] junit.framework.AssertionFailedError: Expected exception: java.lang.RuntimeException
[junit]
[junit]
BUILD FAILED
/opt/project/build/build.xml:88: Test com.company.foo.TestQuoteParser failed
Total time: 1 second
What I'd like is for each test class to get executed, whether or not previous test classes passed or failed, yet still have the overall build fail. It seems like I can either have the build fail on the first failure/error or have all tests run but the build succeeds. I'd also like to get an overall summary printed at the end. Something like this:
Buildfile: /opt/project/build/build.xml
init:
compile:
compiletest:
test:
[junit] Testsuite: com.company.foo.TestQuoteParser
[junit] Tests run: 3, Failures: 1, Errors: 0, Time elapsed: 0.013 sec
[junit]
[junit] Testcase: thisShouldThrowException(com.company.foo.TestQuoteParser): FAILED
[junit] Expected exception: java.lang.RuntimeException
[junit] junit.framework.AssertionFailedError: Expected exception: java.lang.RuntimeException
[junit]
[junit]
[junit] Testsuite: com.company.foo.TestEntityParser
[junit] Tests run: 6, Failures: 1, Errors: 0, Time elapsed: 0.023 sec
[junit]
[junit] Testcase: thisShouldThrowException(com.company.foo.TestEntityParser): FAILED
[junit] Expected exception: java.lang.RuntimeException
[junit] junit.framework.AssertionFailedError: Expected exception: java.lang.RuntimeException
[junit]
[junit]
[junit] Summary: com.company
[junit] Tests run: 9, Failures: 2, Errors: 0, Time elapsed: 0.038 sec
BUILD FAILED
/opt/project/build/build.xml:88: 2 failures
Total time: 1 second
I'd rather get all of this to the screen and not have to go looking at files (even pretty HTML report files), since work will be done via SSH. Is any of that that easily doable?