0
votes

In a project I have a folder src for all application source code and a different folder test for all junit test (both with a simular package hierarchy).

Now I want that Ant can run all tests in in test folder, bot the problem is that now also files in the src folder with "Test" in the filename are included.

This is the test target in the build.xml:

<target name="test" depends="build">
    <mkdir dir="reports/tests" />
    <junit fork="yes" printsummary="yes">
      <formatter type="xml"/>
      <classpath>
        <path location="${build}/WEB-INF/classes"/>
        <fileset dir="${projectname.home}/lib">
            <include name="servlet-api.jar"/>
            <include name="httpunit.jar"/>
            <include name="Tidy.jar"/>
            <include name="js.jar"/>
            <include name="junit.jar"/>
        </fileset>
      </classpath>
      <batchtest todir="reports/tests">
        <fileset dir="${build}/WEB-INF/classes">
            <include name="**/*Test.class"/>
        </fileset>
      </batchtest>
    </junit>
</target>

And I have added the test folder to the build target:

<target name="build" depends="init,init-props,prepare">
    <javac source="1.5" debug="true" destdir="${build}/WEB-INF/classes">
        <src path="src" />
        <src path="test" />
        <classpath refid="classpath"/>
    </javac>
</target>
1

1 Answers

1
votes

Publish test .class files into a separate directory, add this directory to <junit> task class path and scan that secondary directory for **/*Test.class.