question related to junit fork

W

www

Hi,

I am doing junit testing using build.xml and ant. Within build.xml,
there are several targets. If I test individual target, all pass
successfully:
>ant target1 //passes
>ant target2 //passes
>... //all passes

But, if I just do:
>ant test //testing all targets and it fails

I believe it fails because the *Test.class are executed in a random
sequence. But in target1, there are two Java classes, secondTest.class
can only be executed after firstTest.class. "ant target1" will force
such an order and it passes successfully. "ant test" will not guarantee
it so most of time fails. I posted target1 and test part within
build.xml. I have tried using fork as you can see below. I am very new
to junit. I cannot do it right.

Thank you very much for your help.



<part of build.xml>
...
<target name="target1" depends="compile-test, prepare-test">
<delete dir="${test.xml.dir}"/>
<mkdir dir="${test.xml.dir}"/>
<junit errorProperty="test.failed"
failureProperty="test.failed" fork="yes">

<sysproperty key="testfilesdir"
value="${testfiles.dir}"/>
<classpath refid="project.classpath"/>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<batchtest todir="${test.xml.dir}" fork="yes">
<fileset dir="${build.test.dir}"
includes="**/firstTest.class"/>
</batchtest>
</junit>
<copy file="testoutput/tci.xml"
tofile="testoutput/tci.xml.part1"/>
<junit errorProperty="test.failed"
failureProperty="test.failed" fork="yes">
<sysproperty key="testfilesdir"
value="${testfiles.dir}"/>
<classpath refid="project.classpath"/>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<batchtest todir="${test.xml.dir}" fork="yes">
<fileset dir="${build.test.dir}"
includes="**/secondTest.class"/>
</batchtest>
</junit>
<copy file="testoutput/tci.xml"
tofile="testoutput/tci.xml.part2"/>
<fail if="test.failed" message="Build failed because
some test(s) failed."/>
</target>




<target name="test" depends="compile-test, prepare-test" >
<delete dir="${test.xml.dir}"/>
<mkdir dir="${test.xml.dir}"/>
<junit errorProperty="test.failed"
failureProperty="test.failed" fork="on">

<sysproperty key="testfilesdir"
value="${testfiles.dir}"/>

<env key="LD_LIBRARY_PATH"
value="${env.LD_LIBRARY_PATH}:${vendor.lib.dir}"/>

<classpath refid="project.classpath"/>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<batchtest todir="${test.xml.dir}" fork="yes">
<fileset dir="${build.test.dir}"
includes="**/*Test.class"/>
</batchtest>
</junit>
<fail if="test.failed" message="Build failed because
some test(s) failed."/>
</target>

</part of build.xml>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,708
Messages
2,569,347
Members
44,654
Latest member
7Jhamal74

Latest Threads

Top