Ant integrates the JUnit Automatic Test build. XML standard template

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.