using ant to integrate JUnit for Automatic Testing and generate test reports can greatly improve the test efficiency. The advantage is the batch processing function of test cases. Not long ago, I saw a lot of articles about JUnit testing on the Internet: . I'm glad ant has supported JUnit integration and can't wait to try again.
1. Configuration: ant
in this case, APACHE-ant-1.6.5 is used. After downloading ant, copy junit3.8.1 to the lib directory of ant_home. In addition to being visible in classpath, ant must also be visible in ant during testcase execution. Otherwise, an error is reported.
2. directory structure:
working directory
|-Src-|-com-|-Wallace-|-calculator. java
|-test-|-testcalculator. java
|-Lib-|-JUnit. jar
|-build
|-Report
3. template: build. XML
<! -- Configure the runtime classpath -->
<Path id = "classpath. Run">
<Pathelement Path = "$ {classpath}"/>
<Fileset dir = "$ {lib}">
<Include name = "*. Jar"/>
</Fileset>
</Path>
<! -- Configure classpath during testing -->
<Path id = "classpath. Test">
<Path refID = "classpath. Run"/>
<Path location = "$ {Dist}/lib/test-$ {dstamp}. Jar"/>
</Path>
<! -- Task initialization -->
<Target name = "init">
<Tstamp/>
<Delete dir = "$ {build}"/>
<Delete dir = "$ {report}"/>
<Delete dir = "$ {Dist}"/>
<Mkdir dir = "$ {build}"/>
</Target>
<! -- Configure the compilation task -->
<Target name = "compile" depends = "init">
<Javac srcdir = "$ {SRC}" destdir = "$ {build}">
<Classpath refID = "classpath. Run"/>
</Javac>
</Target>
<! -- Configure a packaging task -->
<Target name = "Dist" depends = "compile">
<Mkdir dir = "$ {Dist}/lib"/>
<Jar jarfile = "$ {Dist}/lib/test-$ {dstamp}. Jar" basedir = "$ {build}"/>
</Target>
<! -- Configure the running task -->
<Target name = "run" depends = "compile, DIST">
<Java classname = "com. Test. testcalculator">
<Classpath>
<Path refID = "classpath. Run"/>
</Classpath>
</Java>
</Target>
<! -- Configure the JUnit test and print the test result -->
<Target name = "test" depends = "compile, DIST">
<Mkdir dir = "$ {report. xml}"/>
<Mkdir dir = "zookeeper report.html}"/>
<JUnit printsummary = "yes" haltonfailure = "no">
<Classpath refID = "classpath. Run"/>
<Formatter type = "XML"/>
<Batchtest fork = "yes" todir = "$ {report. xml}">
<Fileset dir = "$ {SRC}" includes = "**/test *. Java"/>
</Batchtest>
</JUnit>
<Junitreport todir = "zookeeper report.html}">
<Fileset dir = "$ {report. xml}">
<Include name = "*. xml"/>
</Fileset>
<Report format = "frames" todir = "repeated bytes report.html}"/>
</Junitreport>
</Target>
</Project> JAVA-Javascript