tags:

views:

3063

answers:

3

We have migrated to both JUnit 4 and ant 1.7

The tests runs fine in eclipse, but the annotations are ignored when running the tests using ant.

According to ant's junit task http://ant.apache.org/manual/OptionalTasks/junit.html%5D">documentation.

It also works with JUnit 4.0, including "pure" JUnit 4 tests using only annotations and no JUnit4TestAdapter.

But the documentation doesn't elaborate on how it should be configured.

Is there any special setting required for the junit task? Am I missing something? We have both Tests that extends TestCase (i.e. 3.8 style) and "pure" Junit 4 tests, could that be the problem?

+5  A: 

Hi, I am using pure JUnit4 tests with ant.

Here is the interesting part of my build file:

<junit printsummary="yes" haltonfailure="yes">
 <formatter type="xml"/>
 <classpath refid="path.test"/>
 <batchtest fork="yes" todir="${dir.report.unittests.xml}">
  <fileset dir="src">
   <include name="**/*Test*.java"/>
  </fileset>
 </batchtest>
</junit>

Make sure you have the latest version of the junit.jar file in the lib directory of ant. As far as I know the required version is delivered with ant 1.7 or higher versions...

Homes2001
So there's no way to avoid having to use a naming pattern for test classes (like "*Test.java") even though JUnit 4 doesn't require that?
Jonik
A: 

This is the relevant part of my generic ant script... not sure if that'll help you or not..

 <junit fork="true"
        forkmode="once"
        haltonfailure="false"
        haltonerror="false"
        failureproperty="tests.failures"
        errorproperty="tests.errors"
        includeantruntime="true"
        showoutput="true"
        printsummary="true">
     <classpath>
         <path refid="path-id.test.classpath.run"/>
     </classpath>

     <formatter type="xml"/>

     <batchtest fork="yes"
                todir="${dir.build.testresults}">
         <fileset dir="${dir.src.tests}">
             <include name="**/*Test.java"/>
         </fileset>
     </batchtest>
 </junit>
TofuBeer
A: 

What I ended up doing was adding an Ant to one of my definitions that is used by the task>. Et voila.