ant+cactus+tomcat5.5 Unit Test in container

Source: Internet
Author: User
Tags tomcat

First, download and decompress cactus

The download address is http://java.chinaitlab.com/tools/45970.html. Copy the Cactus-ant-1.7.1.jar from the Cactus Lib directory to Ant's lib directory.

Second, configure Cactus

The cactus configuration is simple, create a new cactus.properties file, and place it under the classpath of the Cactus task in your ant script, which includes the following

cactus.sysproperties=cactus.contextURL
#cactus-sample-servlet-cactified就是你的测试应用所在路径,8080是端口号
cactus.contextURL = http://localhost:8080/cactus-sample-servlet-cactified
cactus.servletRedirectorName = ServletRedirector
cactus.jspRedirectorName = JspRedirector
cactus.filterRedirectorName = FilterRedirector

The concrete approach is further explained in conjunction with the ant script.

Third, run the ant script

The ant script mainly performs the following tasks

1, set Classpath

<path id="project.classpath">
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
<!-- cactus.properties文件就需要放在lib.dir所对应的路径中 -->
<pathelement location="${lib.dir}"/>
<pathelement location="${tomcat.home}/common/lib/jsp-api.jar"/>
<pathelement location="${tomcat.home}/common/lib/servlet-api.jar"/>
</path>

2. Define Related Tasks

<taskdef resource="cactus.tasks" classpathref="project.classpath"/>
<taskdef name="runservertests" classname="org.apache.cactus.integration.ant.
      RunServerTestsTask">
<classpath>
<path refid="project.classpath"/>
</classpath>
</taskdef>

3, compile the application of the class file and test class file

4, packaging the entire application as a war file

It should be noted that not only do you want to package the application class, the test class will also be packaged

<target name="war" depends="compile.java"
description="Generate the runtime war">
<war warfile="${target.dir}/${project.name}.war"
webxml="${src.webapp.dir}/WEB-INF/web.xml">
<fileset dir="${src.webapp.dir}">
<exclude name="cactus-report.xsl"/>
<exclude name="WEB-INF/cactus-web.xml"/>
<exclude name="WEB-INF/web.xml"/>
</fileset>
<classes dir="${target.classes.java.dir}"/>
<!-- 别忘了打包测试类 -->
<classes dir="${target.classes.test.dir}"/>
<!-- 别忘了打包各种相关的jar文件 -->
< lib dir="project.classpath"/>
</war>
</target>

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.