Junit tests failed when executed by ant but they were successful when I executed them from eclipse. Reason was the dir parameter in junit ant task. It was specifying the the folder which should act as the root folder and this somehow was blocking the classpath specified. and I was looking for a file in the classpath that I had specified in the pathelement.
<target name=”test-html”>
<junit fork=”yes” dir=”${somedirectory.dir.otherthan.what.require}”printsummary=”no” haltonfailure=”no”>
<batchtest fork=”yes” todir=”${test.reports}” >
<fileset dir=”${classes}”>
<include name=”**/*Test.class” />
</fileset>
</batchtest>
<formatter type=”xml” />
<classpath refid=”test.classpath” />
</junit>
<junitreport todir=”${test.reports}”>
<fileset dir=”${test.reports}”>
<include name=”TEST-*.xml” />
</fileset>
<report todir=”${test.reports}” />
</junitreport>
</target>
I was looking for a file which was in d:\testfolder\somefile.properties, and d:\testfolder was defined in <classpath refid=”test.classpath” />. But the test failed since it was looking for the file in ${somedirectory.dir.otherthan.what.require},
To overcome this issue, following was the change.
<target name=”test-html”>
<junit fork=”no” haltonfailure=”no”>
<batchtest fork=”yes” todir=”${test.reports}” >
<fileset dir=”${classes}”>
<include name=”**/*Test.class” />
</fileset>
</batchtest>
<formatter type=”xml” />
<classpath refid=”test.classpath” />
</junit>
<junitreport todir=”${test.reports}”>
<fileset dir=”${test.reports}”>
<include name=”TEST-*.xml” />
</fileset>
<report todir=”${test.reports}” />
</junitreport>
</target>
Advertisement