jenkins the definitive guide

(Jeff_L) #1
<property name="build.dir" value="target" />
<property name="java.classes" value="${build.dir}/classes" />
<property name="test.classes" value="${build.dir}/test-classes" />
<property name="test.reports" value="${build.dir}/test-reports" />
<property name="lib" value="${build.dir}/lib" />

<path id="test.classpath">
<pathelement location="${java.classes}" />
<pathelement location="${lib}" />
</path>

<taskdef resource="testngtasks" classpath="lib/testng.jar"/>

<target name="test" depends="test-compile">
<testng classpathref="test.classpath"
outputDir="${testng.report.dir}"
haltonfailure="no"
failureproperty="failed">
<classfileset dir="${test.classes}">
<include name="**/*Test*.class" />
</classfileset>
</testng>
<fail message="TEST FAILURE" if="failed" />
</target>

TestNG is a very flexible testing library, and the TestNG task has many more options than this. For
example, to only run tests defined as part of the “integration-test” group that we saw earlier, we could
do this:


<target name="integration-test" depends="test-compile">
<testng classpathref="test.classpath"
groups="integration-test"
outputDir="${testng.report.dir}"
haltonfailure="no"
failureproperty="failed">
<classfileset dir="${test.classes}">
<include name="**/*Test*.class" />
</classfileset>
</testng>
<fail message="TEST FAILURE" if="failed" />
</target>

Or to run your tests in parallel, using four concurrent threads, you could do this:


<target name="integration-test" depends="test-compile">
<testng classpathref="test.classpath"
parallel="true"
threadCount=4
outputDir="${testng.report.dir}"
haltonfailure="no"
failureproperty="failed">
<classfileset dir="${test.classes}">
<include name="**/*Test*.class" />
Free download pdf