您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > junit
使用ant進行junit,并生成report
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2014/1/13 11:03:17 ] 推薦標簽:junit ant 測試 單元

  3、antcall,在一個任務(wù)中調(diào)用另一個任務(wù)。例子:

   <target name="exercises">
<property name="directory1" location="d1"/>
<property name="file" location="directory1/a.txt"/>
<echo message="directory = ${directory1}, file=${file}"/>
</target>

<property name="replace1" value="Hello world!!!"/>

<tstamp>
<format property="currenttime" pattern="yyyy-MM-dd'T'HH:mm:ss"/>
</tstamp>
<filterset id="filter.set">
 <filter token="welcome" value="${replace1}" />
 <filter token="time" value="${currenttime}" />
</filterset>
<target name="exercise3">
 <copy todir="d2">
  <fileset dir="d1"/>
  <filterset refid="filter.set"/>
 </copy>
 <antcall target="exercises"/>
</target>

 如果未定義引用property1,則在此處定義它。

6、depend

         <depend srcdir="
                destdir="
                cache="$"
                closure="">
            <include name="**/*.java"/>
        </depend>

8、                  <exec dir="" executable="“
                    <arg line="-lib ${task.lib.dir} -buildfile ${task.ant.file}"/>                 
                  </exec>

試驗成功的一個例子:build.xml

<?xml version="1.0"?>
<project name="Cobra" default="junit" basedir=".">

 <property environment="env" />

 <condition property="ia.home" value="${env.IA_HOME}">
  <isset property="env.IA_HOME" />
 </condition>

 <property name="run.classpath" value="class"></property>
 <property name="run.srcpath" value="../src"></property>
 <property name="test.xml" value="xml"></property>
 <property name="test.report" value="report"></property>
 <property name="lib.dir" value="lib"/>
 
 <path id="compile.path">
  <fileset dir="${lib.dir}">
    <include name="junit.jar" />
    <include name="ant.jar" />
    <include name="ant-xalan1.jar" />
  </fileset>
  <fileset dir="${ia.home}">
    <include name="IAClasses.zip" />
    <include name="resource/services/services.jar" />
    <include name="resource/services/ppk/*.jar" />
    <include name="resource/ant/ant.jar" />
    <include name="resource/log4j-1.2.15.jar" />
  </fileset>
 </path>
 
 <target name="init">     
  <delete dir="${run.classpath}"/>
  <mkdir dir="${run.classpath}"/>
  <delete dir="${test.report}"/>     
  <mkdir dir="${test.report}"/>     
  <delete dir="${test.xml}"/>     
  <mkdir dir="${test.xml}"/>  
 </target>
 
 <target name="compile" depends="init">      
  <javac destdir="${run.classpath}" srcdir="${run.srcpath}" classpathref="compile.path"/>        
 </target>
 
 <target name="junit" depends="compile">     
  <junit printsummary="false">
   <classpath path="${run.classpath}">
    <path refid="compile.path" />
   </classpath>
   <formatter type="xml"/>
   <batchtest todir="${test.xml}">
    <fileset dir="${run.classpath}">
     <include name="**/Test*.class"/>
     <include name="**/*Test.class"/>
    </fileset>
   </batchtest>
  </junit>             
  <junitreport todir="${test.xml}">
   <fileset dir="${test.xml}">
    <include name="TEST-*.xml"/>
   </fileset>
   <report format="frames" todir="${test.report}"/>
  </junitreport>  
 </target>
</project>

上一頁123下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd