To establish a project:
Create a Java project in eclipse.
AntTest
-src
-com.test
-ABS.java
-ABSTest.java (Junit Test Case)
-lib
-build.xml
-JUNIT_HOME/junit.jar
Configuration:
Eclipse->window->preference->ant->runtime->classpath->ant Home Entry
Select Add External JAR and join Eclipse_home/plugins/org.junit.../junit.jar
Content of Build.xml:
1
2.? xml version= "1.0"
3 < Project name = "Project" default = "JUnit"
4 < Propert Y name = "Run.classpath" value = "Bin" ></
5 < property name = "Run.srcpath" value = "src" >< /
6 < property name = "Test.srcpath" value = "src" ></
7 < property name = "T Est.report "value =" "></"
8 < property name = "Lib.dir" value = "Lib"/>
9 < path id = "Compile.path"
< Fileset dir = "${lib.dir}"
< include name = "**/*.jar"/>
/fileset
</path
< target name = "Compile"
< Javac Destdir = "${run.classpath}" "Srcdir =" ${run.srcpath} "Classpathref =" Compile.path "/>
< Javac Destdir =" ${run.classpath} "Srcdir =" ${tes T.srcpath} "classpathref = Compile.path"/>
</target
< target name = "JUnit" depends = "compile "
< TstamP/>
< mkdir dir = "${test.report}"/>
< mkdir dir = "${test.report}/framework-${dstamp}-${tstamp}" "/>
< JUnit printsummary =" true "
N < classpath
< Pathelement path =" ${RUN.CLASSP ATH} "/>
< Fileset dir =" ${lib.dir} "
< include name =" **/*.jar "/>
</ ;
</classpath
< formatter type = "plain"/>
< batchtest fork = "Yes" Todir = "${test.re Port}/framework-${dstamp}-${tstamp} "
< Fileset dir =" ${test.srcpath} "
< include name =" **/*t Est.java "/>
</fileset
</batchtest"
</junit
"</Target
Notoginseng </Project
run:
Right-Build.xml->run as "Ant build".
Results:
The console has output results, such as:
Buildfile:c:\documents and Settings\qianwang\my documents\d\smpworkspace\anttest\build.xml
compile:
junit :
[mkdir] Created dir:c:\documents and Settings\qianwang\my documents\d\smpworkspace\anttest\report\ framework-20070201-1712
[JUnit] Running com.test.ABSTest
[JUnit] Tests Run:3, failures:0, errors:0, Time Elaps ed:0 sec Build
Successful total
time:19 seconds
The result file indicates which testcase were run (indicating the method name test** being tested).
If there is a failures/errors, the details of the exception are also exported here.