1 <?xml version="1.0" encoding="UTF-8"?> 2 <project name="junitDemo02" default="test" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant"> 3 <property name="src.dir" location="src"/> 4 <property name="src.java.dir" location="${src.dir}/java"/> 5 <property name="src.test.dir" location="${src.dir}/test"/> 6 <property name="build.dir" location="build"/> 7 <property name="classes.java.dir" location="${build.dir}/classes/java"/> 8 <property name="classes.test.dir" location="${build.dir}/classes/test"/> 9 <property name="lib.dir" location="lib"/> 10 <property name="test.report.dir" location="${build.dir}/report"/> 11 12 <path id="classpath.java.compile"> 13 <fileset dir="${lib.dir}"> 14 <include name="**/*.jar"/> 15 </fileset> 16 </path> 17 18 <!-- classpath for compiling test source files--> 19 <path id="classpath.test.compile"> 20 <path refid="classpath.java.compile"/> 21 <pathelement location="${classes.java.dir}"/> 22 </path> 23 24 <!-- classpath for running tests --> 25 <path id="classpath.test.run"> 26 <path refid="classpath.test.compile"/> 27 <pathelement location="${classes.test.dir}"/> 28 </path> 29 30 <target name="init" description="--> Init the directories"> 31 <mkdir dir="${src.dir}"/> 32 <mkdir dir="${src.java.dir}"/> 33 <mkdir dir="${src.test.dir}"/> 34 <mkdir dir="${lib.dir}"/> 35 </target> 36 37 <target name="resolve" description="--> resolve all the dependencies by ivy" depends="init"> 38 <ivy:retrieve/> 39 </target> 40 41 <target name="clean" description="--> clean the build directory"> 42 <delete dir="${build.dir}"/> 43 </target> 44 45 <target name="compile.java" description="--> compile all the main java files"> 46 <mkdir dir="${classes.java.dir}"/> 47 <javac destdir="${classes.java.dir}" srcdir="${src.java.dir}" includeAntRuntime="yes"/> 48 </target> 49 50 <target name="compile.test" description="--> compile all the tests source files"> 51 <mkdir dir="${classes.test.dir}"/> 52 <javac destdir="${classes.test.dir}" srcdir="${src.test.dir}" classpathref="classpath.test.compile" includeAntRuntime="yes"/> 53 </target> 54 55 <target name="compile" description="--> compile both main and test source files" depends="clean, compile.java, compile.test"/> 56 57 <target name="test" depends="compile"> 58 <mkdir dir="${test.report.dir}"/> 59 <junit printsummary="yes" fork="yes"> 60 <formatter type="xml"/> 61 <batchtest todir="${test.report.dir}"> 62 <fileset dir="${src.test.dir}"> 63 <include name="**/*Test.java"/> 64 </fileset> 65 </batchtest> 66 <classpath refid="classpath.test.run"/> 67 </junit> 68 </target> 69 70 <target name="report" depends="test" description="--> create the test result report"> 71 <mkdir dir="${test.report.dir}/html"/> 72 <junitreport todir="${test.report.dir}"> 73 <fileset dir="${test.report.dir}"> 74 <include name="TEST-*.xml"/> 75 </fileset> 76 <report todir="${test.report.dir}/html"/> 77 </junitreport> 78 </target> 79 </project>