Before creating any test case you will need Java compiler, Ant and JUnit.
You will also need junit.jar in your Ant's library folder.
Example
<property name="testdir" location="test" />
<property name="srcdir" location="src" />
<property name="full-compile" value="true" />
<path id="classpath.base" />
<path id="classpath.test">
<pathelement location="/apache-ant-1.7.1/lib/junit-3.8.1.jar" />
<pathelement location="/apache-ant-1.7.1/lib/junit-3.8.jar" />
<pathelement location="${testdir}" />
<pathelement location="${srcdir}" />
<path refid="classpath.base" />
</path>
<target name="clean" >
<delete verbose="${full-compile}">
<fileset dir="${testdir}" includes="**/*.class" />
</delete>
</target>
<target name="compile" depends="clean">
<javac srcdir="${srcdir}" destdir="${testdir}" verbose="${full-compile}" >
<classpath refid="classpath.test"/>
</javac>
</target>
<target name="test" depends="compile">
<junit>
<classpath refid="classpath.test" />
<formatter type="brief" usefile="false" />
<test name="JUnitTestExample" />
</junit>
</target>
Create a JUnitTestExample.java file in the src directory as given below.
public class JUnitTestExample extends TestCase {
public void testCase1() {
assertTrue( "TestExample", true );
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.