Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Control JUnit & Ant flow and formatting
    text
    copied!<p>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.</p> <p>Here's what I currently have in the build.xml file:</p> <pre><code> &lt;target name = "test" depends="compiletest" description="run unit tests"&gt; &lt;junit haltonfailure="yes"&gt; &lt;classpath path="${buildtest}"&gt; &lt;path refid="test.classpath"/&gt; &lt;/classpath&gt; &lt;batchtest fork="yes"&gt; &lt;formatter type="brief" usefile="false"/&gt; &lt;fileset dir="${test}"&gt; &lt;include name="**/*Test.java"/&gt; &lt;include name="**/Test*.java"/&gt; &lt;/fileset&gt; &lt;/batchtest&gt; &lt;/junit&gt; &lt;/target&gt; </code></pre> <p>Assuming I have two test classes, each of which has 1 error in it, it would produce the following output:</p> <pre><code>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 </code></pre> <p>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:</p> <pre><code>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 </code></pre> <p>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?</p>
 

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