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