tags:

views:

294

answers:

2

I have made an Ant target that runs my JUnit 4 tests. Unfortunately all of them are executed twice!

Does anyone have an idea of what I have done wrong?

Here are my ant target:

<target name="junit" description="Execute unit tests" depends="compile">
<delete dir="rawtestoutput"/>
<delete dir="test-reports"/>
<mkdir dir="rawtestoutput"/>
<junit printsummary="on" failureproperty="junit.failure" fork="true">
    <classpath refid="class.path.junit"/>
    <formatter type="xml" usefile="true" />
    <batchtest todir="rawtestoutput">
        <fileset dir="src/test">
            <include name="**/*.java"/>

            <!-- Add util and testhelper classes here (to avoid "No tests in class" error) and add suite classes to avoid test being run twice -->
            <exclude name="**/SessionHelper.java"/>
            <exclude name="**/TestHelper.java"/>
            <exclude name="**/AllTests.java"/>
            <exclude name="**/AllEDITests.java"/>
        </fileset>
    </batchtest>
</junit>
<junitreport>
    <fileset dir="rawtestoutput"/>
    <report todir="test-reports"/>
</junitreport>
<fail if="junit.failure" message="Unit test(s) failed.  See reports!"/>
</target>

My first idea was that it because of test suites. But I do not think that anymore. I have excluded the tests suites and furthermore, it not only the tests that are part of suites that are run twice. Its all my tests.

Below is a small sample of the test output of one of my testsclasses:

[20:24:53]: [junit] Running dk.gensam.gaia.business.ydelse.YdelsestypeBOTest
[20:24:53]: [junit] dk.gensam.gaia.business.ydelse.YdelsestypeBOTest (2s)
[20:24:54]:  [dk.gensam.gaia.business.ydelse.YdelsestypeBOTest] loadYdelsevariationer
[20:24:55]:   [loadYdelsevariationer] [Test Output] EMMA: collecting runtime coverage data ...
[20:24:55]:  [dk.gensam.gaia.business.ydelse.YdelsestypeBOTest] loadYdelsestypeIndex_alleExisterendeErAnnullerede
[20:24:56]: [dk.gensam.gaia.business.ydelse.YdelsestypeBOTest] loadYdelsestypeIndex_ingenEksisterendeValgteRelationer
[20:24:56]: [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 3,077 sec
[20:24:56]: dk.gensam.gaia.business.ydelse.YdelsestypeBOTest (3s)
[20:24:56]: [dk.gensam.gaia.business.ydelse.YdelsestypeBOTest] loadYdelsevariationer
[20:24:56]: [dk.gensam.gaia.business.ydelse.YdelsestypeBOTest] loadYdelsestypeIndex_alleExisterendeErAnnullerede
[20:24:56]: [dk.gensam.gaia.business.ydelse.YdelsestypeBOTest] loadYdelsestypeIndex_ingenEksisterendeValgteRelationer

As you can see the tests in YdelsestypeBOTest are run twice...

A: 

It's hard to tell what exactly is happening here but try deleting all your test suites temporarily and recompile just to make sure they are not causing the issue. It looks like you may want to get rid of the test suites anyway if you are starting to move from test suites to using batchtest.

Tony Eichelberger
+2  A: 

From the line:

[20:24:55]: [loadYdelsevariationer] [Test Output] EMMA: collecting runtime coverage data

It looks like a different Ant target is invoking the code coverage tool Emma which is then re-running your tests. If you run your Ant script with this target i.e. ant junit, does it always do this?

DoctorRuss