<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ant+cactus+tomcat5.5容器內單元測試簡明手冊

    摘要:

    折騰了一個星期,終于搞定ant+cactus+tomcat5.5容器內單元測試,為感謝cleverpig斑竹的熱心回貼,特首發于matrix apache版。
    折騰了一個星期,終于搞定ant+cactus+tomcat5.5容器內單元測試,為感謝cleverpig斑竹(http://blog.matrix.org.cn/page/cleverpig)的熱心回貼,特首發于matrix apache版。關于ant的使用,請搜索ant的使用手冊,網上大把中文的。

    一、下載并解壓縮cactus
    下載地址為http://apache.freelamp.com/jakarta/cactus/binaries/jakarta-cactus-12-1.7.1.zip。將cactus的lib目錄下的cactus-ant-1.7.1.jar復制到ant的lib目錄。


    二、配置cactus
    cactus的配置很簡單,新建一個cactus.properties文件,并把它放在ant腳本中的cactus任務的classpath下,文件中包括如下內容
    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

    具體的做法結合ant腳本再進一步解釋。

    三、運行ant腳本
    ??ant腳本主要執行以下任務

    1、設定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、定義相關任務
    ??
    <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、編譯應用的類文件和測試的類文件

    4、打包整個應用為war文件
    需要注意的是,不僅要打包應用類,測試類也要打包
    ??
    ??
    <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>


    5、在應用的web.xml文件中添加測試所需的各種映射
    cactus提供了兩個task來完成這個工作,CactifyWar和WebXmlMerge。
    CactifyWar的功能是自動在已經打包的應用的web.xml文件中添加所需的映射。WebXmlMerge是提供合并兩個web.xml文件的功能。
    <target name="test.prepare"
    ????????????depends="war, compile.cactus, test.prepare.logging">

    ????????<!-- Cactify the web-app archive -->
    ????????<cactifywar srcfile="${target.dir}/${project.name}.war"
    ????????????????????destfile="${tomcat.home}/webapps/${project.name}-cactified.war"
    ????????????????>
    ????????????<classes dir="${target.classes.java.dir}"/>
    ????????????<classes dir="${target.classes.test.dir}"/>
    ????????????<lib dir="project.classpath"/>
    ?????? </cactifywar>
    </target>


    6、運行測試
    cactus提供了cactus和RunServerTests兩個task來運行測試。
    "cactus" task是通過復制容器服務器的最小文件并運行來運行測試,因此需要制定容器服務器的類型,啟動速度稍快點,另外配置比較方便,但是無法測試象tomcat連接池等資源。另外對tomcat5.5的支持也不好。
    "RunServerTests"是通過直接啟動容器服務起來運行測試,因此速度稍慢,且配置較麻煩,但能測試各種資源。
    ??
    <target name="test" depends="test.prepare"
    ???????????? description="Run tests on Tomcat ">

    ????????<!-- Start the servlet engine, wait for it to be started, run the
    ???????????? unit tests, stop the servlet engine, wait for it to be stopped.
    ???????????? The servlet engine is stopped if the tests fail for any reason -->
    ????????<!-- 8080是服務器的端口號,${project.name}-cactified是項目的路徑,和上一步的cactifywar 的destfile相對應 -->
    ????????<runservertests
    ????????????????testURL="http://localhost:8080/${project.name}-cactified/ServletRedirector?Cactus_Service=RUN_TEST"
    ????????????????startTarget="_StartTomcat"
    ????????????????stopTarget="_StopTomcat"
    ????????????????testTarget="_Test"/>

    ????</target>

    ????
    ????
    <!-- _Test就是一個普通的junit任務 -->
    ????<target name="_Test">
    ????????<junit printsummary="yes" fork="yes">
    ????????????<classpath>
    ????????????????<path refid="project.classpath"/>
    ????????????????<pathelement location="${target.classes.java.dir}"/>
    ????????????????<pathelement location="${target.classes.test.dir}"/>
    ????????????</classpath>
    ????????????<formatter type="brief" usefile="false"/>
    ????????????<formatter type="xml"/>

    ????????????<batchtest>
    ????????????????<fileset dir="${src.test.dir}">
    ????????????????????<!-- Due to some Cactus synchronization bug, the 'unit' tests need
    ??????????????to run before the 'sample' tests -->
    ????????????????????<include name="**/Test*.java"/>
    ????????????????????<exclude name="**/Test*All.java"/>
    ????????????????</fileset>
    ????????????</batchtest>
    ????????</junit>
    ????</target>


    posted on 2006-06-12 11:48 nbt 閱讀(226) 評論(0)  編輯  收藏 所屬分類: Java2EE

    <2006年6月>
    28293031123
    45678910
    11121314151617
    18192021222324
    2526272829301
    2345678

    導航

    統計

    常用鏈接

    留言簿(3)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    相冊

    收藏夾

    Java技術網站

    友情鏈接

    國內一些開源網站

    最新隨筆

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲综合男人的天堂色婷婷| 国产国拍亚洲精品mv在线观看| 亚洲第一页在线视频| 光棍天堂免费手机观看在线观看 | 日本一区二区在线免费观看| 四虎在线免费播放| 亚洲av无码一区二区三区在线播放| 一二三四在线播放免费观看中文版视频 | 日韩免费毛片视频| 亚洲爆乳少妇无码激情| 日本高清免费aaaaa大片视频| 老牛精品亚洲成av人片| 亚洲国产高清在线一区二区三区 | 亚洲欧洲第一a在线观看| 人人揉揉香蕉大免费不卡| 亚洲av成人无码久久精品| 亚洲免费人成在线视频观看| 国产亚洲一区二区三区在线| 三上悠亚电影全集免费| 亚洲av中文无码乱人伦在线咪咕| 日本视频免费高清一本18| 亚洲∧v久久久无码精品| 曰批全过程免费视频网址 | 久久精品国产亚洲AV香蕉| 91精品啪在线观看国产线免费| 亚洲美女视频一区二区三区| 免费无码肉片在线观看| 亚洲国产精品18久久久久久| 国产片免费在线观看| 无码日韩人妻AV一区免费l| 亚洲VA成无码人在线观看天堂| 亚洲免费观看在线视频| 亚洲成A人片在线播放器| 免费观看国产精品| 免费无码作爱视频| 亚洲成人黄色在线| 欧美在线看片A免费观看| 在线播放免费人成视频网站| 久久亚洲精品国产精品| 成人免费无遮挡无码黄漫视频| 一级一级一级毛片免费毛片|