Integrating JUnit test results with rosjava

If you have done the basic ant build.xml integration for rosjava, integrating your JUnit test results is easy -- all you have to do is set the directory where your output your test results.

Updating your Ant build file

The ros.properties file declares the ros.test_results property for you. This is the location of the directory to store JUnit XML test results into.

IMPORTANT: you are required to declare an ant target called "test".

Ant lets you write your JUnit tests in a variety of ways. The following snippet is an example that uses the <batchtest> method of generating XML test results to the correct directory. NOTE: ROS tools use the XML form of JUnit reports.

  <target name="test" depends="compile">
    <!-- clear any previous results -->
    <mkdir dir="${ros.test_results}" />
    <delete>
      <fileset dir="${ros.test_results}">
        <include name="*/**" />
      </fileset>
    </delete>
    <junit printsummary="yes" failureproperty="tests.failed">
      <classpath refid="classpath" />
      <formatter type="xml" />
      <batchtest todir="${ros.test_results}">
        <fileset dir="tests">
          <include name="**/*Test.java" />
        </fileset>
      </batchtest>
    </junit>
    <fail if="tests.failed" message="one or more tests failed" />
  </target>

Running your unit tests

To run your tests, simply type:

ant test

Wiki: rosjava/Overview/JUnit (last edited 2011-09-02 18:01:17 by KenConley)