View RSS Feed

My Java Tips

Running JUnit using Ant

Rate this Entry
by , 05-21-2011 at 11:26 PM (2217 Views)
You may want to define build script using ant for your application. I will write about how to create ant script to run ant.

Step 1: define ant properties

XML Code:
<property name="src" value="./src" />
<property name="lib" value="./lib" />
<property name="classes" value="./classes" />
<property name="test.class.name" value="com.xyz.MyTestSuite" />
Step 2: set CLASSPATH to be used by JUnit

XML Code:
<path id="test.classpath">
<pathelement location="${classes}" />
<pathelement location="/path/to/junit.jar" /><fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</path>
Step 3: define the ant task for running JUnit

XML Code:
<target name="test">
<junit fork="yes" haltonfailure="yes">
<test name="${test.class.name}" />
<formatter type="plain" usefile="false" />
<classpath refid="test.classpath" />
</junit>
</target>
Step 4: run the test

Java Code:
ant test

Submit "Running JUnit using Ant" to Facebook Submit "Running JUnit using Ant" to Digg Submit "Running JUnit using Ant" to del.icio.us Submit "Running JUnit using Ant" to StumbleUpon Submit "Running JUnit using Ant" to Google

Tags: ant Add / Edit Tags
Categories
JUnit

Comments