• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2    <head>
3        <title>TestNG - Ant</title>
4
5        <link rel="stylesheet" href="testng.css" type="text/css" />
6        <link type="text/css" rel="stylesheet" href="http://beust.com/beust.css"  />
7        <script type="text/javascript" src="http://beust.com/prettify.js"></script>
8        <script type="text/javascript" src="banner.js"></script>
9
10        <script type="text/javascript" src="http://beust.com/scripts/shCore.js"></script>
11        <script type="text/javascript" src="http://beust.com/scripts/shBrushJava.js"></script>
12        <script type="text/javascript" src="http://beust.com/scripts/shBrushXml.js"></script>
13        <script type="text/javascript" src="http://beust.com/scripts/shBrushBash.js"></script>
14        <script type="text/javascript" src="http://beust.com/scripts/shBrushPlain.js"></script>
15        <link type="text/css" rel="stylesheet" href="http://beust.com/styles/shCore.css"/>
16        <link type="text/css" rel="stylesheet" href="http://beust.com/styles/shThemeCedric.css"/>
17        <script type="text/javascript">
18          SyntaxHighlighter.config.clipboardSwf = 'scripts/clipboard.swf';
19          SyntaxHighlighter.defaults['gutter'] = false;
20          SyntaxHighlighter.all();
21        </script>
22
23</head>
24
25<body onLoad="prettyPrint()">
26
27<script type="text/javascript">
28    displayMenu("ant.html")
29</script>
30
31<h2 align="center">TestNG Ant Task</h2>
32<p>You define the TestNG ant task as follows:</p>
33
34<pre class="brush: xml">
35&lt;taskdef resource="testngtasks" classpath="testng.jar"/&gt;
36</pre>
37
38This task runs TestNG tests and is always run in a forked JVM.&nbsp; It
39accepts the following attributes: <br>
40&nbsp;<table border="2" id="table1">
41	<tr>
42		<th>Attribute </th>
43		<th>Description </th>
44		<th>Required </th>
45	</tr>
46	<tr>
47		<td><tt>classfilesetref</tt> </td>
48		<td>A reference to a
49		<a href="http://ant.apache.org/manual/Types/resources.html#collection">ResourceCollection</a>
50		containing the test classes to be run. Only File based
51                <a href="http://ant.apache.org/manual/Types/resources.html#collection">ResourceCollection</a>s
52                are supported (ie. <a href="http://ant.apache.org/manual/Types/fileset.html">FileSet</a>).</td>
53		<td>&nbsp; </td>
54	</tr>
55	<tr>
56		<td><tt>classpath</tt> </td>
57		<td>A PATH-like structure for the tests to be run. </td>
58		<td>&nbsp; </td>
59	</tr>
60	<tr>
61		<td><tt>classpathref</tt> </td>
62		<td>A reference to a PATH-like structure for the tests to be run. </td>
63		<td>&nbsp; </td>
64	</tr>
65	<tr>
66		<td><tt>configFailurePolicy</tt> </td>
67		<td>Whether TestNG should <tt>continue</tt> to execute the remaining tests in the suite or <tt>skip</tt> them if an @Before* method fails.</td>
68		<td>No. Defaults to <tt>skip</tt></td>
69	</tr>
70	<tr>
71		<td><tt>dataProviderThreadCount</tt> </td>
72		<td>The number of threads to use for data providers
73		for this run. Ignored unless the parallel mode is also specified</td>
74		<td>1</td>
75	</tr>
76	<tr>
77		<td><tt>delegateCommandSystemProperties</tt> </td>
78		<td>Pass the command line properties as system properties.</td>
79		<td>No. Defaults to false </td>
80	</tr>
81	<tr>
82		<td><tt>dumpCommand</tt> </td>
83		<td>Print the TestNG launcher command. </td>
84		<td>No. Defaults to false </td>
85	</tr>
86	<tr>
87		<td><tt>failureProperty</tt> </td>
88		<td>The name of a property to set in the event of a failure. It is used
89		only if the <tt>haltonfailure</tt> is not set. </td>
90		<td>No.</td>
91	</tr>
92	<tr>
93		<td><tt>haltonfailure</tt> </td>
94		<td>Stop the build process if a failure has occurred during the test
95		run. </td>
96		<td>No. Defaults to false
97		</td>
98		<td>&nbsp;</td>
99	</tr>
100	<tr>
101		<td><tt>haltonskipped</tt> </td>
102		<td>Stop the build process if there is at least on skipped test. </td>
103		<td>No. Default to false </td>
104	</tr>
105	<tr>
106	  <td><tt>groups</tt></td>
107	  <td>
108   	The list of groups to run, separated by spaces or commas.</td>
109	  <td>
110   	</td>
111	</tr>
112	<tr>
113	  <td><tt>excludedgroups</tt></td>
114	  <td>
115   	The list of groups to exclude, separated by spaces or commas</td>
116	  <td>
117   	</td>
118	</tr>
119	<tr>
120		<td><tt>jvm</tt></td>
121		<td>The JVM to use, which will be run by <tt>Runtime.exec()</tt></td>
122		<td><tt>java</tt></td>
123	</tr>
124	<tr>
125		<td><tt>listeners</tt></td>
126		<td>A comma or space-separated list of fully qualified classes that are TestNG listeners (for example<tt>
127		<a href="http://testng.org/javadocs/org/testng/ITestListener.html">
128		org.testng.ITestListener</a></tt> or <tt>
129		<a href="http://testng.org/javadocs/org/testng/IReporter.html">
130		org.testng.IReporter</a>)</tt></td>
131		<td>No.</td>
132	</tr>
133
134        <tr>
135		<td><tt>methods</tt></td>
136		<td>A comma separated list of fully qualified class name and method. For example <tt>com.example.Foo.f1,com.example.Bar.f2</tt>.</td>
137		<td>No.</td>
138        </tr>
139
140        <tr>
141		<td><tt>mode</tt></td>
142                <td>Either <tt>"testng"</tt>, <tt>"junit"</tt> or <tt>"mixed"</tt>. Whether TestNG should run only TestNG tests, JUnit tests or both.</td>
143		<td>No. Defaults to "testng".</td>
144        </tr>
145
146	<tr>
147		<td><tt>outputdir</tt> </td>
148		<td>Directory for reports output.
149		</td>
150		<td>No. Defaults to <tt>test-output</tt>. </td>
151	</tr>
152	<tr>
153		<td><tt>skippedProperty</tt> </td>
154		<td>The name of a property to set in the event of a skipped test. It is
155		used only if the <tt>haltonskipped</tt> is not set. </td>
156		<td>No. </td>
157	</tr>
158	<tr>
159		<td><tt>suiteRunnerClass</tt> </td>
160		<td>A fully qualified name of a TestNG starter. </td>
161		<td>
162		<p align="left">No.&nbsp; Defaults to <tt>
163		<a href="http://testng.org/javadocs/org/testng/TestNG.html">org.testng.TestNG</a> </tt></td>
164	</tr>
165
166	<tr>
167		<td><tt>suiteThreadPoolSize</tt> </td>
168		<td>The size of a thread pool to run suites.</td>
169		<td>
170		<p align="left">No.&nbsp; Defaults to 1.</td>
171	</tr>
172
173	<tr>
174		<td><tt>parallel</tt> </td>
175		<td>The parallel mode to use for running the tests - either methods or tests</td>
176		<td>No - if not present, parallel mode will not be selected</td>
177	</tr>
178
179	<tr>
180		<td><tt>suitename</tt> </td>
181		<td>Sets the default name of the test suite, if one is not specified in a suite xml file or in the source code</td>
182		<td>No. Defaults to "Ant suite"</td>
183	</tr>
184
185	<tr>
186		<td><tt>testJar</tt> </td>
187		<td>Path to a jar containing tests and a suite definition. </td>
188		<td>&nbsp;</td>
189	</tr>
190
191	<tr>
192		<td><tt>testname</tt> </td>
193		<td>Sets the default name of the test, if one is not specified in a suite xml file or in the source code</td>
194		<td>No. defaults to "Ant test"</td>
195	</tr>
196
197	<tr>
198		<td><tt>testnames</tt> </td>
199		<td>A comma separated list of test names, as defined
200		in the &lt;test&gt; tag. Only these tests will be run.</td>
201		<td>No. defaults to "Ant test"</td>
202	</tr>
203
204	<tr>
205		<td><tt>threadCount</tt> </td>
206		<td>The number of threads to use for this run. Ignored unless the parallel mode is also specified</td>
207		<td>1</td>
208	</tr>
209
210	<tr>
211		<td><tt>timeOut</tt></td>
212		<td>The maximum time out in milliseconds that all the tests should run
213		under.</td>
214		<td>&nbsp;</td>
215	</tr>
216
217	<tr>
218		<td><tt>useDefaultListeners</tt></td>
219		<td>Whether the default listeners and reporters should be used.</td>
220		<td>Defaults to true.</td>
221	</tr>
222	<tr>
223		<td><tt>workingDir</tt></td>
224		<td>The directory where the ant task should change to before running
225		TestNG.</td>
226		<td>&nbsp;</td>
227	</tr>
228	<tr>
229		<td><tt>xmlfilesetref</tt> </td>
230		<td>A reference to a
231		<a href="http://ant.apache.org/manual/Types/resources.html#collection">ResourceCollection</a>
232		containing the suite definitions to be run. Only File based
233                <a href="http://ant.apache.org/manual/Types/resources.html#collection">ResourceCollection</a>s
234                are supported (ie. <a href="http://ant.apache.org/manual/Types/fileset.html">FileSet</a>).</td>
235		<td>&nbsp; </td>
236	</tr>
237
238	<tr>
239		<td><tt>xmlPathInJar</tt></td>
240		<td>The path of the XML file inside the jar file, only applicable if <tt>testJar</tt> was specified</td>
241		<td>testng.xml</td>
242	</tr>
243</table>
244<br>
245One of attributes <tt>classpath</tt>, <tt>classpathref</tt> or nested <tt>
246&lt;classpath&gt;</tt> must be used for providing the tests classpath.
247<p>One of the attributes <tt>xmlfilesetref</tt>, <tt>classfilesetref</tt> or
248nested <tt>&lt;xmlfileset&gt;</tt>, respectively <tt>&lt;classfileset&gt;</tt> must be used
249for providing the tests. </p>
250
251<h3>TestNG modes</h3>
252<p>The TestNG mode gets applied when tests are passed to TestNG using <tt>classfilesetref</tt>, <tt>methods</tt>
253or nested <tt>&lt;classfileset&gt;</tt> and tells TestNG what kind of
254tests it should look for and run:
255
256<ul>
257  <li><tt>"testng"</tt>: find and run TestNG tests.
258  <li><tt>"junit"</tt>: find and run JUnit tests.
259  <li><tt>"mixed"</tt>: run both TestNG and JUnit tests.
260</ul>
261
262<p><em>Note</em>: <tt>"junit"</tt> and <tt>"mixed"</tt> modes require the JUnit jar file on the classpath.</p>
263
264<h3><a name="nested">Nested Elements</a></h3>
265<h4>classpath</h4>
266<p>The <tt>&lt;testng&gt;</tt> task supports a nested <tt>&lt;classpath&gt;</tt> element
267that represents a <em>PATH</em>-like structure. </p>
268<h4>bootclasspath</h4>
269<p>The location of bootstrap class files can be specified using this <em>
270PATH-like</em> structure - will be ignored if <tt>fork </tt>is not set. </p>
271<h4>xmlfileset</h4>
272<p>The suite definitions (<tt>testng.xml</tt>) can be passed to the task with a
273<tt><a href="http://ant.apache.org/manual/Types/fileset.html">FileSet</a></tt>
274structure. </p>
275<h4>classfileset</h4>
276<p>TestNG can also run directly on classes, also supplied with a <tt>
277<a href="http://ant.apache.org/manual/Types/fileset.html">FileSet</a></tt>
278structure.</p>
279<h4>jvmarg</h4>
280<p>Additional parameters may be passed to the new VM via nested <tt>&lt;jvmarg&gt;</tt>
281elements. For example: </p>
282
283<pre class="brush: xml">
284&lt;testng&gt;
285   &lt;jvmarg value="-Djava.compiler=NONE" /&gt;
286   &lt;!-- ... --&gt;
287&lt;/testng&gt;
288</pre>
289
290<h4>sysproperty</h4>
291<p>Use nested <tt>&lt;sysproperty&gt;</tt> elements to specify system properties
292required by the class. These properties will be made available to the virtual
293machine during the execution of the test. The attributes for this element are
294the same as for <em>environment variables</em>:</p>
295
296<pre class="brush: xml">
297&lt;testng&gt;
298   &lt;sysproperty key="basedir" value="${basedir}"/&gt;
299   &lt;!-- ... --&gt;
300&lt;/testng&gt;
301</pre>
302
303<p>will run the test and make the <code>basedir</code> property
304available to the test.</p>
305
306<h4>propertyset</h4>
307<p>You may also use a nested <tt>&lt;propertyset&gt;</tt> element to specify a set of system properties that are defined
308outside of the TestNG ant task. This allows for more flexible definitions of system properties, for instance selecting
309all properties with a specific prefix or matching a regex. See the
310<a href="http://ant.apache.org/manual/Types/propertyset.html">PropertySet page</a> in the
311<a href="http://ant.apache.org/manual/">Ant manual</a> for full details. Here's a simple example:</p>
312<pre class="brush: xml">
313      &lt;property name="myprop1" value="value 1"/&gt;
314      &lt;property name="myprop2" value="value 2"/>
315
316      &lt;propertyset id="propset1"&gt;
317          &lt;propertyref name="myprop1"/&gt;
318          &lt;propertyref name="myprop2"/&gt;
319      &lt;/propertyset&gt;
320
321      &lt;testng outputdir="${testng.report.dir}" classpathref="run.cp"&gt;
322          &lt;xmlfileset dir="${test15.dir}" includes="testng-single3.xml"/&gt;
323          &lt;propertyset refid="propset1"/&gt;
324      &lt;/testng&gt;
325</pre>
326<p>In this case, the system properties named "myprop1" and "myprop2" are passed along to the TestNG process.</p>
327
328<h4>reporter</h4>
329<p>An inner <tt>&lt;reporter&gt;</tt> element is an alternative way to inject a
330custom report listener allowing the user to set custom properties in order to fine-tune
331the behavior of the reporter at run-time.
332<br>
333The element has one <tt>classname</tt> attribute which is mandatory, indicating
334the class of the custom listener. In order to set the properties of the reporter, the
335<tt>&lt;reporter&gt;</tt> element can contain several nested <tt>&lt;property&gt;</tt>
336elements which will provide the <tt>name</tt> and <tt>value</tt> attributes as seen below:
337</p>
338<pre class="brush: xml">
339&lt;testng ...&gt;
340   ...
341   &lt;reporter classname="com.test.MyReporter"&gt;
342      &lt;property name="methodFilter" value="*insert*"/&gt;
343      &lt;property name="enableFiltering" value="true"/&gt;
344   &lt;/reporter&gt;
345   ...
346&lt;/testng&gt;
347</pre>
348<pre class="brush: java">
349public class MyReporter {
350
351  public String getMethodFilter() {...}
352  public void setMethodFilter(String methodFilter) {...}
353  public boolean isEnableFiltering() {...}
354  public void setEnableFiltering(boolean enableFiltering) {...}
355  ...
356}
357</pre>
358You have to consider though that for the moment only a limited set of property types are supported:
359<tt>String, int, boolean, byte, char, double, float, long, short</tt>.
360
361<h4>env</h4>
362<p>It is possible to specify environment variables to pass to the TestNG forked
363virtual machine via nested <tt>&lt;env&gt;</tt> elements. For a description of the <tt>
364&lt;env&gt;</tt> element's attributes, see the description in the <em>
365<a href="http://ant.apache.org/manual/CoreTasks/exec.html">exec</a></em> task.</p>
366<h3>Examples</h3>
367<h4>Suite xml</h4>
368
369<pre class="brush: text">
370&lt;testng classpathref="run.cp"
371        outputDir="${testng.report.dir}"
372        sourcedir="${test.src.dir}"
373        haltOnfailure="true"&gt;
374
375   &lt;xmlfileset dir="${test14.dir}" includes="testng.xml"/&gt;
376&lt;/testng&gt;
377</pre>
378
379<h4>Class FileSet</h4>
380<pre class="brush: xml">
381&lt;testng classpathref="run.cp"
382		outputDir="${testng.report.dir}"
383		haltOnFailure="true" verbose="2"&gt;
384	&lt;classfileset dir="${test.build.dir}" includes="**/*.class" /&gt;
385&lt;/testng&gt;
386</pre>
387
388<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
389</script>
390<script type="text/javascript">
391_uacct = "UA-238215-2";
392urchinTracker();
393</script>
394
395</body>
396
397</html>
398