运行 JUnit

以下将在匹配 test/**/*Test.java 的测试上运行 JUnit。这需要 junit.jar 在 lib 文件夹中。

<project name="Project" default="junit" basedir=".">
    <path id="classpath">
        <fileset dir="lib" includes="**/*.jar"/>
        <pathelement path="build"/>
    </path>

    <target name="compile">
        <javac srcdir="test" destdir="build" classpathref="classpath"/>
    </target>

    <target name="junit" depends="compile">
        <junit fork="true" logfailedtests="false">
            <classpath refid="classpath"/>
            <batchtest>
                <fileset dir="test" includes="**/*Test.java"/>
                <formatter type="plain" usefile="false"/>
            </batchtest>
        </junit>
    </target>
</project>