In this tutorial, we will show you how to run a TestNG test in Ant build. 1. Run by Classes build.xml <taskdef name="testng" classname="org.testng.TestNGAntTask"> <classpath location="lib/testng-6.8.14.jar" /> </taskdef> <target name="testng" depends="compile"> <!– Assume test.path contains the project library dependencies –> <testng classpathref="test.path" outputDir="${report.dir}" haltOnFailure="true"> <!– Extra project classpath, which is not included in above "test.path" […]

Read more Ant and TestNG Task example

In this tutorial, we will show you how to run a junit test in Ant build. 1. Run a unit test build.xml <target name="junit" depends="compile"> <junit printsummary="yes" haltonfailure="no"> <!– Project classpath, must include junit.jar –> <classpath refid="test.path" /> <!– test class –> <classpath location="${test.classes.dir}" /> <test name="com.mkyong.test.TestMessage" haltonfailure="no" todir="${report.dir}"> <formatter type="plain" /> <formatter type="xml" /> […]

Read more Ant and jUnit Task example

Declares a junit task in Ant like this build.xml <!– Run jUnit –> <target name="junit" depends="resolve"> <junit printsummary="yes" haltonfailure="no"> <classpath refid="test.path" /> <classpath location="${build.dir}" /> <test name="com.mkyong.test.TestMessage" haltonfailure="no" todir="${report.dir}" outfile="result"> <formatter type="plain" /> <formatter type="xml" /> </test> </junit> </target> Run ant junit, but hits the following error message : BUILD FAILED build.xml:86: The <classpath> for […]

Read more Must include junit.jar if not in Ant’s own classpath

In Ant, you can use pathconvert task to print out the classpath from path : build.xml <path id="project.web.classpath"> <pathelement location="test/lib/junit-4.11.jar"/> <pathelement location="test/lib/hamcrest-core-1.3.jar"/> <fileset dir="${lib.web.dir}"> <include name="**/*.jar" /> </fileset> </path> <target name="print-classpath"> <pathconvert property="classpathInName" refid="project.web.classpath" /> <echo>Classpath is ${classpathInName}</echo> </target> Test : $ ant print-classpath Buildfile: /Users/mkyong/Documents/workspace/AntSpringMVC/build.xml print-classpath: [echo] Classpath is /Users/mkyong/Documents/workspace/AntSpringMVC/test/lib/junit-4.11.jar: /Users/mkyong/Documents/workspace/AntSpringMVC/testlib/hamcrest-core-1.3.jar: …… BUILD SUCCESSFUL […]

Read more Ant – How to print classpath from path id

Here’s a Apache Ant template file , best use to start a project from scratch. File : build.xml <project name="ProjectName" default="dist" basedir="."> <description> Project Description </description> <!– set global properties for this build –> <property name="projectName" value="ProjectName"/> <property name="src" location="src"/> <property name="build" location="build"/> <property name="dist" location="dist"/> <property name="webcontent" location="WebContent"/> <target name="init"> <!– Create the time […]

Read more Ant Template file to build a Java Project