<target name="-init-macrodef-junit">
    <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
        <attribute default="${includes}" name="includes"/>
        <attribute default="${excludes}" name="excludes"/>
        <attribute default="**" name="testincludes"/>
        <element name="customize" optional="true"/>
        <sequential>
            <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true">
                <batchtest todir="${build.test.results.dir}" unless="test.method">
                    <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
                        <filename name="@{testincludes}"/>
                    </fileset>
                </batchtest>
                <customize/>
                <classpath>
                    <path path="${run.test.classpath}"/>
                </classpath>
                <syspropertyset>
                    <propertyref prefix="test-sys-prop."/>
                    <mapper from="test-sys-prop.*" to="*" type="glob"/>
                </syspropertyset>
                <formatter type="brief" usefile="false"/>
                <formatter type="xml"/>
                <jvmarg line="${run.jvmargs}"/>
            </junit>
        </sequential>
    </macrodef>
</target>

<target name="-check-can-run-tests" depends="init,compile-test-single,-pre-test-run-single" if="have.tests">
    <condition property="run.test.method">
        <isset property="test.method"/>
    </condition>
    <condition property="run.test.class">
        <not>
            <isset property="test.method"/>
        </not>
    </condition>
</target>

<target name="-do-test-run-single-method" depends="-check-can-run-tests" if="run.test.method">
    <fail unless="test.class">Must also set test.class if test.method is specified</fail>
    <fail message="Execution of a single test method is not supported by this version of Ant.">
        <condition>
            <not>
                <available classname="org.apache.tools.ant.taskdefs.optional.junit.XMLResultParser">
                    <classpath path="${run.test.classpath}"/>
                </available>
            </not>
        </condition>
    </fail>
    <j2seproject3:junit excludes="**">
        <customize>
            <test name="${test.class}" methods="${test.method}" todir="${build.test.results.dir}"/>
        </customize>
    </j2seproject3:junit>
</target>

<target name="-do-test-run-single-class" depends="-check-can-run-tests" if="run.test.class">
    <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
    <j2seproject3:junit excludes="" includes="${test.includes}"/>
</target>

<target name="-do-test-run-single" depends="-do-test-run-single-method,-do-test-run-single-class"/>