利用Ant自动进行JUnit测试

build.xml 代码
  1. <?xml version="1.0"?>  
  2.   
  3. <project name="auto unittest task" default="junit and report" basedir="..">  
  4.   
  5.     <!-- property name="output folder" value="bin"/-->  
  6.   
  7.     <property name="output folder" value="WebRoot/WEB-INF/classes" />  
  8.   
  9.   
  10.     <property name="lib folder" value="WebRoot/WEB-INF/lib" />  
  11.   
  12.     <property name="src folder" value="src" />  
  13.   
  14.     <property name="httpUnit folder" value="E:/lxy/lib/httpUnit" />  
  15.   
  16.     <!-- property name="test folder" value="src"/-->  
  17.   
  18.     <property name="test folder" value="testSrc" />  
  19.   
  20.     <property name="report folder" value="report" />  
  21.        
  22.     <property name="jar.dir" value="jar" />  
  23.   
  24.     <target name="test init">  
  25.         <delete dir="${report folder}" />  
  26.         <mkdir dir="${report folder}" />  
  27.         <echo>test init complete!</echo>  
  28.     </target>  
  29.   
  30.     <target name="compile">  
  31.         <javac srcdir="${src folder}" destdir="${output folder}" />  
  32.         <echo>compilation complete!</echo>  
  33.     </target>  
  34.   
  35.     <target name="test compile" depends="test init">  
  36.         <javac srcdir="${test folder}" destdir="${output folder}" />  
  37.         <echo>test compilation complete!</echo>  
  38.     </target>  
  39.   
  40.     <target name="all compile" depends="compile, test compile">  
  41.     </target>  
  42.   
  43.     <target name="junit and report" depends="all compile">  
  44.         <junit printsummary="on" fork="true" showoutput="true">  
  45.             <classpath>  
  46.                 <fileset dir="${lib folder}" includes="**/*.jar" />  
  47.                 <fileset dir="${httpUnit folder}" includes="**/*.jar" />  
  48.                 <pathelement path="${output folder}" />  
  49.             </classpath>  
  50.             <formatter type="xml" />  
  51.             <batchtest todir="${report folder}">  
  52.                 <fileset dir="${output folder}">  
  53.                     <!-- include name="**/Test*.*" /-->  
  54.                     <!-- include name="**/*Test*.*" /-->  
  55.                     <include name="**/*Test.*" />  
  56.                 </fileset>  
  57.             </batchtest>  
  58.         </junit>  
  59.         <junitreport todir="${report folder}">  
  60.             <fileset dir="${report folder}">  
  61.                 <include name="TEST-*.xml" />  
  62.             </fileset>  
  63.             <report format="frames" todir="${report folder}" />  
  64.         </junitreport>  
  65.     </target>  
  66.        
  67.     <!-- 打包成jar文件 -->  
  68.     <target name="jar" depends="all compile">  
  69.         <delete file="${jar.dir}/eweb.jar" />  
  70.         <jar jarfile="${jar.dir}/eweb.jar">  
  71.             <fileset dir="${output folder}">  
  72.                 <include name="**/*.class" />  
  73.                 <include name="**/*.xml" />  
  74.                 <include name="**/*.properties" />  
  75.             </fileset>  
  76.         </jar>  
  77.     </target>  
  78.   
  79. </project>  

你可能感兴趣的:(xml,Web,ant,JUnit)