Alex Rivera | Logout

Running Junit through Ant does not seem to use custom class runner

Asked 2011-10-17T15:53:46.823
8

I have a custom runner that ships Junit tests over a socket connection to a Junit server running on other hardware. The tests run as intended with the following target:

    <target name="run">
        <mkdir dir="reports" />
        <junit fork="yes" haltonfailure="no">
            <test name="${CurrentTest}" />
            <formatter type="xml" />
            <classpath refid="mastersuite.classpath" />
        </junit>

        <junitreport todir="${JunitReport.dir}">
            <fileset dir=".">
                <include name="TEST-*.xml" />           
            </fileset>
            <report todir="${JunitReport.dir}" />
        </junitreport>
    </target>

However, when I add in the following <batchtest> element...

<target name="run">
    <delete dir="reports" failonerror="false" />        
    <!-- Make the reports directory -->
    <mkdir dir="reports" />

    <!-- Execute the tests and saves the results to XML -->
    <junit fork="yes" printsummary="no" haltonfailure="no">
        <batchtest fork="yes" todir="${JunitReport.dir}">
            <fileset dir="${APITesting.classes}">
                <include name="test/api/**/*Test.class" />
            </fileset>
        </batchtest>
        <formatter type="xml" />
        <classpath refid="mastersuite.classpath" />
    </junit>

    <!-- Compile the resulting XML file into an HTML based report. -->
    <junitreport todir="${JunitReport.dir}">
        <fileset dir="${JunitReport.dir}">
            <include name="TEST-*.xml" />
        </fileset>
        <report todir="${JunitReport.dir}" />
    </junitreport>
</target>

nothing gets shipped over to the hardware, which leads me to believe that my @RunWith(com.company.name.Re

Edit
Report

1 Answer

10

It seems that Ant automatically resolves which runner to use based on if your test case uses the Junit4TestAdapter. I ended up having to add the following method to all of my test cases:

public class MyTestCase extends TestCase
    public static junit.framework.Test suite() {
        return new JUnit4TestAdapter(MyTestCase.class);
    }
    ...
}

Most of you will probably not need to extend TestCase, but in my case this is required because Junit4 is acting as a client to a Junit3 server.

answered 2011-10-18T18:59:17.307

Your Answer