Here is an example explaining an ant task for generating TestNG report after execution of classes defined in TestNG xml file.
Below is the testNG file that is used in the above build file.
//TestNG.xml
- <property name="src.dir" value="src" />
- <property name="lib.dir" value="lib" />
- <property name="log.dir" value="logs" />
- <property name="build.loc" value="build" />
- <property name="classes.dir" value="${build.loc}/classes" />
- <property name="reports.dir" value="${build.loc}/reports" />
- <property name="testNG.report" value="${reports.dir}/TestNG" />
- <property name="suite.dir" value="suite" />
- <!-- Class-Path -->
- <path id="classpath">
- <pathelement location="${classes.dir}"/>
- <fileset dir="${lib.dir}" includes="*.jar"/>
- </path>
- <!-- Delete directories that are not needed -->
- <target name="delete-dir" >
- <delete dir="${build.loc}"/>
- <echo> /* Deleted existing Compiled Directory Classes */ </echo>
- </target>
- <!-- Create Directories -->
- <target name="create-source-dir" depends="delete-dir">
- <mkdir dir="${classes.dir}"/>
- <mkdir dir="${testNG.report}"/>
- <echo> /* Created Directories */ </echo>
- </target>
- <!-- Compiling Tests -->
- <target name="compile-classes" depends="create-source-dir">
- <javac destdir="${classes.dir}" includeantruntime="false" debug="true" srcdir="${src.dir}">
- <classpath refid="classpath"/>
- </javac>
- <echo> /* Compiled Directory Classes */ </echo>
- </target>
- <!-- Running Tests and TestNG report generation -->
- <target name="testNGreport" depends="compile-classes">
- <taskdef resource="testngtasks" classpathref="classpath"/>
- <testng classpathref="classpath" outputDir="${testNG.report}" haltOnfailure="true">
- <xmlfileset dir="." includes="${suite.dir}/testng.xml" />
- </testng>
- <echo> /* Run Directory Classes */ </echo>
- </target>
Below is the testNG file that is used in the above build file.
//TestNG.xml
- <suite name="Suite1" verbose="1" >
- <test name="Regression1">
- <classes>
- <class name="test.sample.ExampleTest1"/>
- <class name="test.sample.ExampleTest2"/>
- </classes>
- </test>
- </suite>
No comments:
Post a Comment