2
votes

I have this and works fine:

<target name="runjunit">
    <junit>
        <classpath>
            <pathelement path="${build}"/>
            <fileset dir="lib">
                <include name="*.jar"/>
            </fileset>
        </classpath> 
        <test name="com.xyzcompany.abcproject.test.junit.CalculatorTest"/>
        <formatter type="brief" usefile="false"/>
    </junit>
</target>

However, I have multiple tests. So I do this:

<target name="runjunit">
    <junit>
        <classpath>
            <pathelement path="${build}"/> <---- this doesn't seem to work anymore
            <fileset dir="lib">
                <include name="*.jar"/>
            </fileset>
        </classpath> 
        <batchtest>
            <fileset dir="com/xyzcompany/abcproject/test/junit">
                <include name="**/*.*"/>
            </fileset>
        </batchtest>
        <formatter type="brief" usefile="false"/>
    </junit>
</target>

However, that tells me the directory doesn't exist:

C:\Users\me\Desktop\repository\mainproj\trunk\com\xyzcompany\abcproject\test\junit does not exist.

The above should be:

C:\Users\me\Desktop\repository\mainproj\trunk\build\com\xyzcompany\abcproject\test\junit

As you see, the pathelement in classpath would set trunk/build/com in the single test, but doesn't in batchtest.

Directory and package names obfuscated for privacy.

Any idea how I can change the batchtest so pathelement in classpath actually works? Thanks!

EDIT:

This doesn't work:

<batchtest>
    <fileset dir="${build}/com/xyzcompany/abcproject/test/junit">
        <include name="**/*.*" />
    </fileset>
</batchtest>

It gives me:

java.lang.ClassNotFoundException: CalculatorTest

Setting it to <fileset dir="${build}/com/xyzcompany/abcproject/test/junit"> doesn't make any sense since the class doesn't know it is under build. Thus, setting the classpath is the correct option, but doesn't work for <batchtest>.

EDIT 2:

Now that I really think about it, it does make sense to do <fileset dir="${build}/com/xyzcompany/abcproject/test/junit">. However, when it spins up java for junit it doesn't run junit from the ${build} classpath.

EDIT 3:

<batchtest>
    <fileset dir="${build}">
        <include name="com/xyzcopmany/abcproject/test/junit/*"/>
    </fileset>
</batchtest>

Final answers. Ant should really have better documentation. It is a complex product...

2

2 Answers

3
votes

set

<fileset dir="com/xyzcompany/abcproject/test/junit">

to

<batchtest>
    <fileset dir="${buildTests}">
        <include name="**/*Test*.class"/>
    </fileset>
</batchtest>

Do not include com/xyzcompany/abcproject/test/junit part in the ${buildTests}.

0
votes

If you want to pick up the files for your batch test from ${build} directory, you should tell so

    <batchtest>
        <fileset dir="${build}/com/xyzcompany/abcproject/test/junit">
            <include name="**/*"/>
        </fileset>
    </batchtest>