2009年10月15日 星期四

Junit 4: Add Junit test on Ant

<target name="mytest" description="mytest">

<junit printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="yes"> <formatter type="plain" usefile="false" />

<test name="gov.hud.mfh.business.service.contracts.ContractFinderTest"/> <classpath>
<pathelement path="test"/> <!-- source code place -->
<fileset dir="test"> <!-- source lib place -->
<include name="**/*.jar"/>
<exclude name="**/ant*.jar"/>
</fileset>
<fileset dir="./lib/junit"> <!-- junit lib place -->
<include name="**/*.jar"/>
<exclude name="**/ant*.jar"/>
</fileset> </classpath>
</junit>
</target>

You must Exclude ant*.jar otherwise you will get Error:
No tests found in gov.hud.mfh.business.service.contracts
And USE ANT 1.7.0 TO RUN JUNIT 4.
ANT 1.7.1 might has problem.

Batch Junit Example

<target name="batchtest" description="batchtest">
<junit printsummary="yes" haltonerror="no" haltonfailure="yes" fork="yes">
<formatter type="xml" usefile="true" />
<classpath>
<pathelement path="test"/>
<fileset dir="test">
<include name="**/*.jar"/>
<exclude name="**/ant*.jar"/>
</fileset>
<fileset dir="./lib/junit">
<include name="**/*.jar"/>
<exclude name="**/ant*.jar"/>
</fileset>
</classpath>
<batchtest fork="yes" todir="${reports.junit.dir}" haltonfailure="yes" >
<fileset dir="junit">
<include name="**/*Test*.java"/>
</fileset>
<formatter type="xml"/>
</batchtest>
</junit>
</target>

沒有留言:

張貼留言