Junit fork=”yes” dir=”${some.dir}” sets the working dir to ${some.dir} which ignores classpath specified in the test

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.