Using Ant to execute junit in eclipse

Source: Internet
Author: User
Tags mkdir

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.

Related Article

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.