1<project name="testng" default="all" basedir="."> 2 3 <property file="build.properties"/> 4 5 <property name="report.dir" value="${test.output.dir}"/> 6 <property name="junit.report.dir" value="${report.dir}/test-tmp"/> 7 <property name="testng.report.dir" value="${report.dir}"/> 8 9 <target name="all" depends="prepare,compile,run,reports,done"/> 10 11 <!-- ==================================================================== --> 12 <!-- Compile --> 13 <!-- ==================================================================== --> 14 <path id="compile.cp"> 15 <pathelement location="${testng.jar}" /> 16 <fileset dir="${lib.dir}" includes="${guice2.jar}" /> 17 <fileset dir="${lib.dir}" includes="${junit.jar}" /> 18 <fileset dir="${lib.dir}" includes="aopalliance-1.0.jar" /> 19 </path> 20 21 <target name="env:info"> 22 <echo> 23BASEDIR =${basedir} 24TEST.DIR =${test.dir} 25TEST.BUILD.DIR =${test.build.dir} 26REPORT.DIR =${report.dir} 27JUNIT.REPORT.DIR =${junit.report.dir} 28TESTNG.REPORT.DIR=${testng.report.dir} 29 </echo> 30 </target> 31 32 <target name="compile" depends="prepare"> 33 <echo message=" -- Compiling tests --"/> 34 35 <property name="build.compiler" value="modern"/> 36 <javac debug="true" 37 source="1.7" 38 classpathref="compile.cp" 39 srcdir="${test.dir}" 40 destdir="${test.build.dir}" 41 /> 42 43 </target> 44 45 <target name="prepare"> 46 <tstamp/> 47 <mkdir dir="${test.build.dir}"/> 48 <mkdir dir="${junit.report.dir}"/> 49 <mkdir dir="${testng.report.dir}"/> 50 51 <taskdef name="testng" 52 classname="org.testng.TestNGAntTask" 53 classpath="${build.dir}"/> 54 </target> 55 56<!-- 57 <property name="cobertura.dir" value="../cobertura-1.9.4.1" /> 58 59 <path id="cobertura.classpath"> 60 <fileset dir="${cobertura.dir}"> 61 <include name="cobertura.jar" /> 62 <include name="lib/**/*.jar" /> 63 </fileset> 64 </path> 65--> 66 67 <!-- ==================================================================== --> 68 <!-- Run --> 69 <!-- ==================================================================== --> 70 71 <path id="run.cp"> 72<!-- 73 <path location="target/instrumented-classes" /> 74 <path refid="cobertura.classpath" /> 75--> 76 <path refid="compile.cp"/> 77 <pathelement location="${test.build.dir}"/> 78 </path> 79 80 <target name="run" description="Run tests" depends="compile,copy-resources"> 81 <echo message=" -- Running tests --"/> 82 <echo message=" -- ${testng.jar} --" /> 83 <testng classpathref="run.cp" 84 outputdir="${testng.report.dir}"> 85 <xmlfileset dir="${test.resources.dir}" includes="testng.xml"/> 86 <jvmarg value="-Dtest.resources.dir=${test.resources.dir}" /> 87 <jvmarg value="-Dsun.io.serialization.extendedDebugInfo=true" /> 88 </testng> 89 </target> 90 91 <target name="copy-resources" description="Copies resources."> 92 <copy verbose="false" 93 file="${src.resources.dir}/testngtasks" 94 todir="${build.dir}" /> 95 <copy todir="${build.dir}"> 96 <fileset dir="${src.resources.dir}"> 97 <exclude name="**/.*" /> 98 <exclude name="**/CVS/*" /> 99 </fileset> 100 </copy> 101 </target> 102 103 <target name="run:single" description="Run 1 property file named with the ant property test" depends="compile"> 104 <echo message=" -- testng-tests-run1 --"/> 105 106 <testng outputdir="${testng.report.dir}" 107 classpathref="run.cp" 108 useDefaultListeners="true" 109 outputDir="${testng.report.dir}"> 110 <xmlfileset dir="${test.resources.dir}" includes="testng-single.xml"/> 111 </testng> 112 113 <echo>Report created in open ${testng.report.dir}/index.html</echo> 114 </target> 115 116 <target name="run:antprop" description="Run a test to see if ant system propertes are passed correctly" depends="compile"> 117 <echo message=" -- testng-tests-run-antprop --"/> 118 <property name="syspropset1" value="value 1"/> 119 <property name="syspropset2" value="value 2"/> 120 <propertyset id="propset1"> 121 <propertyref name="syspropset1"/> 122 <propertyref name="syspropset2"/> 123 </propertyset> 124 125 <testng outputdir="${testng.report.dir}" 126 classpathref="run.cp"> 127 <xmlfileset dir="${test.resources.dir}" includes="testng-single3.xml"/> 128 <propertyset refid="propset1"/> 129 <sysproperty key="sysprop1" value="value 3"/> 130 </testng> 131 </target> 132 133 <!-- ==================================================================== --> 134 <!-- Run specific configuration --> 135 <!-- ==================================================================== --> 136 <target name="run:conf" 137 if="testng.conf" 138 depends="clean:reports,compile" 139 description="Run specified tests"> 140 <echo message=" -- testng-tests-run --"/> 141 <echo message="using: ${testng.conf}.xml"/> 142 143 <testng classpathref="run.cp" 144 outputDir="${testng.report.dir}"> 145 <xmlfileset dir="${test.resources.dir}" includes="${testng.conf}.xml"/> 146 </testng> 147 148 <antcall target="clean.tmp"/> 149 </target> 150 151 152 <!-- ==================================================================== --> 153 <!-- Reports --> 154 <!-- ==================================================================== --> 155 156 <target name="reports"> 157 <junitreport todir="${junit.report.dir}"> 158 <fileset dir="${testng.report.dir}"> 159 <include name="*.xml"/> 160 <exclude name="testng-failed.xml"/> 161 <exclude name="testng-results.xml" /> 162 </fileset> 163 <report format="noframes" todir="${junit.report.dir}"/> 164 </junitreport> 165 </target> 166 167 168 <target name="clean.tmp"> 169 <delete dir="${test.output.dir}"/> 170 </target> 171 172 <target name="clean:reports"> 173 <delete dir="${report.dir}"/> 174 <delete dir="${junit.report.dir}"/> 175 </target> 176 177 <target name="clean" depends="clean.tmp,clean:reports"> 178 <echo message=" -- test clean --"/> 179 180 <delete dir="${test.build.dir}"/> 181 </target> 182 183 <target name="done"> 184 <echo>Reports can be found in: open ${testng.report.dir}/index.html</echo> 185 </target> 186 187</project> 188