Automatically test JUnit with Ant

Source: Internet
Author: User
Tags mkdir

One, the configuration of the jar package required to support ant <junit> tasks.

Note:this task depends on external libraries not included in the Ant distribution. dependencies for more information.

Note: The JUnit character relies on an optional library, not included in the standard Ant.jar.

Note:you must have Junit.jar and the class files for the <junit> task in the same classpath. Can do one of:

Note: You must have Junit.jar, and this class file must be under the same ant path

Put both Junit.jar and the optional tasks jar file in Ant_home/lib.

1, put the Junit.jar and optional task jar (Optional.jar) files into the Ant_home/lib directory. environment variable ant_home = **\ant such a directory.

Don't put either in Ant_home/lib, and instead include their locations in your CLASSPATH environment.

2, if you do not put the Junit.jar and optional task jar (Optional.jar) files into the Ant_home/lib directory, you can do this by writing the absolute path (including the filename) of the two jar files into your system environment variable CLASSPATH.

Do neither of the above, and instead, specify their locations using a <classpath> element in the build file. The FAQ for details.

3, if you do not want to do the above 2 methods, then you can:

In build file ant, use the <classpath> element to specify the location of the Junit.jar and optional task jar (Optional.jar) files.

Here are some examples of success:

<?xml version= "1.0"
<project name= "project" default= "JUnit"
<property name= " Run.classpath "value=" Bin "></property>"
<property name= "Run.srcpath" value= "src" ></property
<property name= "Test.srcpath" value= "test" ></PROPERTY>
<property name= "Test.report" Value= "></property>"
<property name= "Lib.dir" Value= "Lib"/>
<path id= "Compile.path"
<fileset dir= "${lib.dir}"
<include name= "**/*.jar"/>
</fileset>
</path
<!--compilation Classpath
<path id= "Compile.classpath"
<fileset dir= "${telecom_" LDBS.lib} "
<include name=" **/*.jar "/>
</fileset>
</path>
;
<target Name= "Compile"
<javac destdir= "${run.classpath}" srcdir= "${run.srcpath}"
classpathref= "Compile.path" "/>
<javac destdir=" ${run.classpath} "srcdir=" ${test.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"
<classpath
<pathelement path= "${run.classpath}"/>
< Fileset dir= "${lib.dir}"
<include name= "**/*.jar"/>
</fileset>
</classpath>
<!--
<test name= "Ldbs1adslsectionbaseinfomodelservicetest" ></TEST>

<formatter Type= "plain"/>
<!--She zhi Yao ce shi de Wen Jian ji he;
<batchtest fork= "yes" todir= Rt}/framework-${dstamp}-${tstamp} "
<fileset dir=" ${test.srcpath} "
<include name=" **/* Test.java "/>
</fileset>
</batchtest>
</junit>
</target>
</project

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.