I'm trying to automate running JUnit tests through Ant. I have a test that executes on average in about 1.5 seconds. It runs fine if I run the test through the Eclipse plug-in, but times out when I try to run it from Ant. Here is my Ant script:

<target name="junit">
  <junit fork="yes" forkmode="perTest" printsummary="yes" haltonfailure="no" timeout="10000">
    <classpath refid="junit.class.path" />
    <test name="classname" haltonfailure="no" todir=".\Reports"> 
      <formatter type="xml" />
    </test>
  </junit>
</target>

I have also added

@Test(timeout = 10000)

to the test method and

@Rule
public Timeout globalTimeout = new Timeout(10,TimeUnit.SECONDS);

to the test class.

Adding the @Test in the source corrected the issue when the test is run from Eclipse, but doesn't seem to work when the test is run from Ant. The timeout=10000 in the Ant script does not seem to work either. The Ant script does work for other tests by changing the classname.

I'm pretty new to Ant and JUnit. Have I missed something? Any ideas?

Thanks.

0 Answers