James Raitsev
James Raitsev

Reputation: 96371

Running jUnit tests via ANT, clarification needed

Suppose you have a test directory that contains packages each of which contains jUnit tests.

In this setup, using ANT, how would you "run all tests?"

Assuming my jUnit has

<target name="test" depends="compileTest">
    <junit fork="yes" printsummary="yes" haltonfailure="no">

        <classpath location="${bin}" />

        <formatter type="plain" />
        <test name="_com.??.project.alltests.MyTests" />

    </junit>
</target>

Where, MyTests has

@RunWith(Suite.class)
@Suite.SuiteClasses( { _ThisTest.class, _ThatTest.class })
public class OCTTests {

}

and _ThisTest itself contains some tests ..

Is it possible for the purposes of ANT script to avoid this ans simply say "Run all Tests you find in this directory"

Upvotes: 0

Views: 503

Answers (1)

FrVaBe
FrVaBe

Reputation: 49341

Have a look at the nested batchtest element of the junit task. You will find the following example on the junit task documentation page:

<junit printsummary="yes" haltonfailure="yes">
  <classpath>
    <pathelement location="${build.tests}"/>
    <pathelement path="${java.class.path}"/>
  </classpath>

  <formatter type="plain"/>

  <test name="my.test.TestCase" haltonfailure="no" outfile="result">
    <formatter type="xml"/>
  </test>

  <batchtest fork="yes" todir="${reports.tests}">
    <fileset dir="${src.tests}">
      <include name="**/*Test*.java"/>
      <exclude name="**/AllTests.java"/>
    </fileset>
  </batchtest>
</junit>

Upvotes: 1

Related Questions