Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit gives no information regarding "errors"

Tags:

java

junit

ant

I'm using Junit 4.4 and Ant 1.7. If a test case fails with an error (for example because a method threw an unexpected exception) I don't get any details about what the error was.

My build.xml looks like this:

<target name="test" depends="compile">
<junit printsummary="withOutAndErr" filtertrace="no" fork="yes" haltonfailure="yes" showoutput="yes">
  <classpath refid="project.run.path"/>
  <test name="a.b.c.test.TestThingee1"/>
  <test name="a.b.c.test.NoSuchTest"/>
</junit>
</target>

When I run "ant test" it says (for example) 2 Test runs, 0 failures, 1 error. It doesn't say "There is no such test as NoSuchTest" even though this is completely reasonable and would let me figure out the cause of the error.

Thanks!

-Dan

like image 809
user41762 Avatar asked Nov 29 '08 07:11

user41762


2 Answers

Figured it out :)

I needed to add a "formatter" inside the junit block.

<formatter type="plain" usefile="false" />

What a PITA.

-Dan

like image 116
user41762 Avatar answered Oct 19 '22 04:10

user41762


If you're going to have a lot of tests there are two change you might want to consider:

  1. run all the tests rather than stopping at the first error
  2. create a report showing all the test results

And it is pretty easy to do with the junitreport task:

<target name="test">
    <mkdir dir="target/test-results"/>
    <junit fork="true" forkmode="perBatch" haltonfailure="false"
           printsummary="true" dir="target" failureproperty="test.failed">
        <classpath>
            <path refid="class.path"/>
            <pathelement location="target/classes"/>
            <pathelement location="target/test-classes"/>
        </classpath>
        <formatter type="brief" usefile="false" />
        <formatter type="xml" />
        <batchtest todir="target/test-results">
            <fileset dir="target/test-classes" includes="**/*Test.class"/>
        </batchtest>
    </junit>

    <mkdir dir="target/test-report"/>
    <junitreport todir="target/test-report">
        <fileset dir="target/test-results">
            <include name="TEST-*.xml"/>
        </fileset>
        <report format="frames" todir="target/test-report"/>
    </junitreport>

    <fail if="test.failed"/>
</target>
like image 35
Jeffrey Fredrick Avatar answered Oct 19 '22 03:10

Jeffrey Fredrick