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

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

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

    ant+cactus+tomcat5.5容器內(nèi)單元測試

    Posted on 2009-06-22 15:06 林光炎 閱讀(456) 評論(0)  編輯  收藏 所屬分類: JAVA
     一、下載并解壓縮cactus
      下載地址為http://Java.chinaitlab.com/tools/45970.Html 。將cactus的lib目錄下的cactus-ant-1.7.1.jar復(fù)制到ant的lib目錄。
      二、配置cactus
      cactus的配置很簡單,新建一個cactus.properties文件,并把它放在ant腳本中的cactus任務(wù)的classpath下,文件中包括如下內(nèi)容
      cactus.sysproperties=cactus.contextURL
      #cactus-sample-servlet-cactified就是你的測試應(yīng)用所在路徑,8080是端口號
      cactus.contextURL = http://localhost:8080/cactus-sample-servlet-cactified
      cactus.servletReDirectorName = ServletRedirector
      cactus.jspRedirectorName = JspRedirector
      cactus.filterRedirectorName = FilterRedirector
      具體的做法結(jié)合ant腳本再進一步解釋。
      三、運行ant腳本
       ant腳本主要執(zhí)行以下任務(wù)
      1、設(shè)定classpath
      <path id="project.classpath">
       <fileset dir="${lib.dir}">
       <include name="*.jar"/>
       </fileset>
       <!-- cactus.properties文件就需要放在lib.dir所對應(yīng)的路徑中 -->
       <pathelement location="${lib.dir}"/>
       <pathelement location="${tomcat.home}/common/lib/jsp-api.jar"/>
       <pathelement location="${tomcat.home}/common/lib/servlet-api.jar"/>
       </path>
      2、定義相關(guān)任務(wù)
      <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、編譯應(yīng)用的類文件和測試的類文件
      4、打包整個應(yīng)用為war文件
      需要注重的是,不僅要打包應(yīng)用類,測試類也要打包
      <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}"/>
       <!-- 別忘了打包各種相關(guān)的jar文件 -->
       < lib dir="project.classpath"/>
       </war>
       </target>
      5、在應(yīng)用的web.xml文件中添加測試所需的各種映射
      cactus提供了兩個task來完成這個工作,CactifyWar和WebXmlMerge。
      CactifyWar的功能是自動在已經(jīng)打包的應(yīng)用的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是通過復(fù)制容器服務(wù)器的最小文件并運行來運行測試,因此需要制定容器服務(wù)器的類型,啟動速度稍快點,另外配置比較方便,但是無法測試象tomcat連接池等資源。另外對tomcat5.5的支持也不好。
      "RunServerTests"是通過直接啟動容器服務(wù)起來運行測試,因此速度稍慢,且配置較麻煩,但能測試各種資源。
      <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是服務(wù)器的端口號,${project.name}-cactified是項目的路徑,和上一步的cactifywar 的destfile相對應(yīng) -->
       <runservertests
       testURL="http://localhost:8080/${project.name}-cactified/ServletRedirector?Cactus_Service=RUN_TEST"
       startTarget="_StartTomcat"
       stopTarget="_StopTomcat"
       testTarget="_Test"/>
       </target>
      <!-- _Test就是一個普通的junit任務(wù) -->
       <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>
      文章來源: baike.duba.net

    posts - 104, comments - 33, trackbacks - 0, articles - 0

    Copyright © 林光炎

    主站蜘蛛池模板: 亚洲av无码一区二区三区不卡| 亚洲av麻豆aⅴ无码电影| 国产亚洲人成网站在线观看不卡| 老司机午夜免费视频| 国产精品无码素人福利免费| 亚洲色大成网站WWW国产| 巨胸喷奶水视频www网免费| 亚洲AV男人的天堂在线观看| 性xxxxx免费视频播放| 亚洲欧洲日产v特级毛片| 精品福利一区二区三区免费视频| 亚洲一本综合久久| 亚洲国产精品免费视频| 中文字幕亚洲第一在线| 亚洲日本在线免费观看| 亚洲日本久久久午夜精品 | 成在人线av无码免费高潮水| 亚洲色偷偷狠狠综合网| 四虎影视无码永久免费| 亚洲av中文无码乱人伦在线r▽ | 亚洲欧洲自拍拍偷综合| 噼里啪啦免费观看高清动漫4 | 亚洲第一区视频在线观看| 性xxxxx免费视频播放| 亚洲日韩av无码中文| 亚洲国产成人a精品不卡在线| 波霸在线精品视频免费观看| 久久久久亚洲AV无码网站| 无码国产精品久久一区免费| 在线精品自拍亚洲第一区| 亚洲日韩激情无码一区| 亚洲人成在线免费观看| 国产精品亚洲专区无码不卡| 亚洲精品自产拍在线观看| 国产精品久久免费| 无人视频免费观看免费视频| 亚洲日本精品一区二区 | 国产国拍精品亚洲AV片 | 国产高清在线精品免费软件| 国产一级一毛免费黄片| 亚洲看片无码在线视频|