James Raitsev
James Raitsev

Reputation: 96461

Running jUnit with ANT - How to execute all tests without using @Suite?

I'd like to execute all tests in a /test directory without using annotations such as

@Suite.SuiteClasses( ....)

In the past i had a single class, which was calling many other classes to test them all. This approach is no longer acceptable.

I have a /test directory, underneath which i have a number of packages, each containing several tests.

In my current ANT script, i have:

<target name="compileTest" depends="compile" description="compile jUnit">
    <javac srcdir="${test}" destdir="${bin}" includeantruntime="true" />
</target>

followed by

<target name="test" depends="compileTest">
    <junit printsummary="yes" fork="no" haltonfailure="no">
        <classpath location="${bin}" />
        <formatter type="plain" />
    </junit>
</target>

In the past, i had

<test name="MyCollectionOfTests" />

I'd rather not do this anymore.

What am i missing? Please advise.

Upvotes: 1

Views: 2504

Answers (1)

tonio
tonio

Reputation: 10541

You can use a nested batchtest. For instance:

<junit printsummary="on"
       fork="on"
       dir="${test.build}"
       haltonfailure="false"
       failureproperty="tests.failed"
       showoutput="true">
  <classpath>
    <path refid="tests.classpath"/>
 </classpath>
 <batchtest todir="${test.report}">
    <fileset dir="${test.gen}">
      <include name="**/Test*.java"/>
    </fileset>
    <fileset dir="${test.src}">
      <include name="**/Test*.java"/>
      <exclude name="gen/**/*"/>
    </fileset>
  </batchtest>
</junit>

In its simplest form, you can simply add a nested:

<batchtest todir="report">
  <fileset dir="test"/>
</batchtest>

to your junit call.

Upvotes: 3

Related Questions