ajay mehra wrote:
> can anyone help me how we can launch our testNG test using ant.till now i
> was executing my testcases in the commandline and it was succesfull.and i
> dont have any idea about how to make a ant script for my testng tests to
> launch it with ant.so if possible please provide me a sample ant buildfile
> so that i can implement it in my testNG test.
> the version of ant i am using is apache-ant-1.7.1 and my testNG version is
> testNG-5.9.
>
Here is a simple Ant build.xml file that might get you going,
but to help yourself with this you must please Read The Fine Manuals
at
http://testng.org/doc/ant.html
and
http://ant.apache.org/manual/index.html
<project name="testng.example" basedir="." default="help">
<property name="src.java" value="src/java"/>
<property name="target.java" value="target/classes"/>
<property name="logdir" value="target/logs"/>
<property name="project.root" location="."/>
<property name="libs" location="${project.root}/libs"/>
<property name="tools.testng.jar" location="${libs}/testng/
testng-5.10-jdk15.jar"/>
<path id="classpath.compile">
<fileset dir="${libs}" includes="*.jar"/>
</path>
<path id="classpath.run.tests">
<pathelement location="${target.java}"/>
<pathelement location="${tools.testng.jar}"/>
<fileset dir="${libs}" includes="*.jar"/>
</path>
<target name="help">
<exec osfamily="windows" executable="cmd">
<arg value="/c"/>
<arg value="ant.bat"/>
<arg value="-projecthelp"/>
<arg value="-buildfile"/>
<arg value="${ant.file}"/>
</exec>
<exec osfamily="unix" executable="ant">
<arg value="-projecthelp"/>
<arg value="-buildfile"/>
<arg value="${ant.file}"/>
</exec>
</target>
<target name="run" depends="taskdef.testng, init">
<pathconvert refid="classpath.run.tests" property="crt" pathsep="$
{line.separator}"/>
<echo>Classpath for running these tests:${line.separator}${crt}</
echo>
<testng classpathref="classpath.run.tests"
useDefaultListeners="true"
outputDir="${logdir}"
verbose="1">
<!--jvmarg value="-
agentlib:jdwp=transport=dt_socket,server=y,address=8000"/-->
<classfileset dir="${target.java}" includes="**/*.class"/>
<reporter classname="reports.TestNameReporter"/>
<sysproperty key="wss.test.formatter.debug" value="true"/>
</testng>
</target>
<target name="taskdef.testng" description="TestNG - see
http://testng.org/doc/ant.html" >
<taskdef resource="testngtasks">
<classpath><pathelement location="${tools.testng.jar}"/></
classpath>
</taskdef>
</target>
<target name="compile" depends="init">
<javac destdir="${target.java}" classpathref="classpath.compile"
source="1.6"
target="1.6"
debug="on"
debuglevel="lines,source,vars"
optimize="on"
memoryMaximumSize="256m"
fork="false">
<src path="${src.java}"/>
</javac>
<copy todir="${target.java}" failonerror="false">
<fileset dir="${src.java}" includes="**/*" excludes="**/*.java" /
>
</copy>
</target>
<target name="clean">
<delete dir="${target.java}"/>
<delete dir="${logdir}"/>
<mkdir dir="${target.java}"/>
<mkdir dir="${logdir}"/>
</target>
<target name="init">
<mkdir dir="${target.java}"/>
<mkdir dir="${logdir}"/>
</target>
</project>