3

I have a problem with my unit test, and I don't have a clue why. When I run my unit test normally in eclipse it runs perfectly fine. But when I try to build my project using ant, there is a unit test that fails.

The only information that I get from it is that the test failed, I don't know why or on what line.

Is there a way for me to let ant tell me what went wrong (and on which line)?

This is my unit test target:

  <target name="unit.test"
          depends="jar"
          description="'jar', 'compile', and run unit tests">
    <junit printsummary="on" failureproperty="unit.test.failed" timeout="300000">
      <jvmarg value="-Dtest.resource.dir=${resource.dir}/test"/>
      <jvmarg value="-Dresource.dir=${resource.dir}"/>
      <jvmarg value="-Djava.awt.headless=true"/>
      <classpath >
        <pathelement location="${debug.class.dir}"/>
        <pathelement location="${resource.test.dir}"/>
        <pathelement location="${resource.dir}"/>
        <pathelement location="${library.release.dir}/${junit.jar}"/>
        <filelist refid="test.imports"/>
        <filelist refid="imports"/>
      </classpath>
      <formatter type="xml"/>

      <batchtest fork="yes" todir="${release.test.dir}">
        <fileset dir="${source.dir}">
          <include name="test/unit/**/*Test.java" unless="test.unit"/>
          <include name="test/unit/**/${test.unit}Test.java" if="test.unit"/>
          <exclude name="test/unit/**/Abstract*.java"/>
        </fileset>
      </batchtest>

    </junit>
    <fail message="one or more unit test failed" if="unit.test.failed"/>
  </target>

This is what it looks like in my console:

unit.test:

[junit] Running test.unit.com.bazinga.sensormonitor.IBoxSensorDeviceTest

[junit] Tests run: 9, Failures: 0, Errors: 0, Time elapsed: 4.049 sec

[junit] Running test.unit.com.bazinga.sensormonitor.M2MSensorDeviceTest

[junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 1.586 sec

[junit] Running test.unit.com.bazinga.sensormonitor.RMoniSensorDeviceTest

[junit] Tests run: 21, Failures: 0, Errors: 1, Time elapsed: 5.385 sec

[junit] Test test.unit.com.bazinga.sensormonitor.RMoniSensorDeviceTest FAILED

[junit] Running test.unit.com.bazinga.sensormonitor.SensiteSensorDeviceTest

[junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 1.303 sec

[junit] Running test.unit.com.bazinga.sensormonitor.TBoxSensorDeviceTest

[junit] Tests run: 10, Failures: 0, Errors: 0, Time elapsed: 2.055 sec

BUILD FAILED

/home/user/projects/bazinga/admin/build/ant-library.xml:150: one or more unit test failed

Thanks for your help.

4

2 回答 2

1

Maybe showoutput=true is what you are searching for? This would sned the test output to the console in addition to the logging files.

http://ant.apache.org/manual/Tasks/junit.html

于 2013-08-06T08:50:14.720 回答
1

Normally one will not look at console for failure details. The standard junit task collect all information in result files ( under ${release.test.dir} in your case). Junit report task provides a html view of test result.

Most CI has

于 2013-08-06T09:02:52.780 回答