1 | <html>
|
---|
2 | <head>
|
---|
3 | <title>JUnit Task</title>
|
---|
4 | <link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
|
---|
5 | </head>
|
---|
6 | <body>
|
---|
7 |
|
---|
8 | <h2><a name="junit">JUnit</a></h2>
|
---|
9 | <h3>Description</h3>
|
---|
10 |
|
---|
11 | <p>This task runs tests from the JUnit testing framework. The latest
|
---|
12 | version of the framework can be found at
|
---|
13 | <a href="http://www.junit.org">http://www.junit.org</a>.
|
---|
14 | This task has been tested with JUnit 3.0 up to JUnit 3.8.1; it won't
|
---|
15 | work with versions prior to JUnit 3.0.</p>
|
---|
16 | <p><strong>Note:</strong> This task depends on external libraries not included
|
---|
17 | in the Ant distribution. See <a href="../install.html#librarydependencies">
|
---|
18 | Library Dependencies</a> for more information.
|
---|
19 | </p>
|
---|
20 | <p>
|
---|
21 | <strong>Note</strong>:
|
---|
22 | You must have <code>junit.jar</code> and the class files for the
|
---|
23 | <code><junit></code> task in the same classpath.
|
---|
24 | You can do one of:
|
---|
25 | <ol>
|
---|
26 | <li>
|
---|
27 | Put both <code>junit.jar</code> and the optional tasks jar file in
|
---|
28 | <code>ANT_HOME/lib</code>.
|
---|
29 | </li>
|
---|
30 | <li>
|
---|
31 | Do not put either in <code>ANT_HOME/lib</code>, and instead
|
---|
32 | include their locations in your <code>CLASSPATH</code> environment variable.
|
---|
33 | </li>
|
---|
34 | <li>
|
---|
35 | Do neither of the above, and instead, specify their locations using
|
---|
36 | a <code><classpath></code> element in the build file.
|
---|
37 |
|
---|
38 | See <a href="../../faq.html#delegating-classloader" target="_top">the
|
---|
39 | FAQ</a> for details.
|
---|
40 | </ol>
|
---|
41 | </p>
|
---|
42 |
|
---|
43 |
|
---|
44 | <p>Tests are defined by nested <code>test</code> or
|
---|
45 | <code>batchtest</code> tags (see <a href="#nested">nested
|
---|
46 | elements</a>).</p>
|
---|
47 |
|
---|
48 | <h3>Parameters</h3>
|
---|
49 | <table border="1" cellpadding="2" cellspacing="0">
|
---|
50 | <tr>
|
---|
51 | <td width="12%" valign="top"><b>Attribute</b></td>
|
---|
52 | <td width="78%" valign="top"><b>Description</b></td>
|
---|
53 | <td width="10%" valign="top"><b>Required</b></td>
|
---|
54 | </tr>
|
---|
55 | <tr>
|
---|
56 | <td valign="top">printsummary</td>
|
---|
57 | <td valign="top">Print one-line statistics for each testcase. Can
|
---|
58 | take the values <code>on</code>,
|
---|
59 | <code>off</code>, and
|
---|
60 | <code>withOutAndErr</code>.
|
---|
61 | <code>withOutAndErr</code> is the same
|
---|
62 | as <code>on</code> but also includes the output of the test
|
---|
63 | as written to <code>System.out</code> and <code>System.err</code>.</td>
|
---|
64 | <td align="center" valign="top">No; default is <code>off</code>.</td>
|
---|
65 | </tr>
|
---|
66 | <tr>
|
---|
67 | <td valign="top">fork</td>
|
---|
68 | <td valign="top">Run the tests in a separate VM.</td>
|
---|
69 | <td align="center" valign="top">No; default is <code>off</code>.</td>
|
---|
70 | </tr>
|
---|
71 | <tr>
|
---|
72 | <td valign="top">forkmode</td>
|
---|
73 | <td valign="top">Controls how many Java Virtual Machines get
|
---|
74 | created if you want to fork some tests. Possible values are
|
---|
75 | "perTest" (the default), "perBatch" and
|
---|
76 | "once". "once" creates only a single Java VM
|
---|
77 | for all tests while "perTest" creates a new VM for each
|
---|
78 | TestCase class. "perBatch" creates a VM for each nested
|
---|
79 | <code><batchtest></code> and one collecting all nested
|
---|
80 | <code><test></code>s. Note that only tests with the same
|
---|
81 | settings of <code>filtertrace</code>, <code>haltonerror</code>,
|
---|
82 | <code>haltonfailure</code>, <code>errorproperty</code> and
|
---|
83 | <code>failureproperty</code> can share a VM, so even if you set
|
---|
84 | <code>forkmode</code> to "once", Ant may have to create
|
---|
85 | more than a single Java VM. This attribute is ignored for tests
|
---|
86 | that don't get forked into a new Java VM. <em>since Ant 1.6.2</em></td>
|
---|
87 | <td align="center" valign="top">No; default is <code>perTest</code>.</td>
|
---|
88 | </tr>
|
---|
89 | <tr>
|
---|
90 | <td valign="top">haltonerror</td>
|
---|
91 | <td valign="top">Stop the build process if an error occurs during the test
|
---|
92 | run.</td>
|
---|
93 | <td align="center" valign="top">No; default is <code>off</code>.</td>
|
---|
94 | </tr>
|
---|
95 | <tr>
|
---|
96 | <td valign="top">errorproperty</td>
|
---|
97 | <td valign="top">The name of a property to set in the event of an error.</td>
|
---|
98 | <td align="center" valign="top">No</td>
|
---|
99 | </tr>
|
---|
100 | <tr>
|
---|
101 | <td valign="top">haltonfailure</td>
|
---|
102 | <td valign="top">Stop the build process if a test fails (errors are
|
---|
103 | considered failures as well).</td>
|
---|
104 | <td align="center" valign="top">No; default is <code>off</code>.</td>
|
---|
105 | </tr>
|
---|
106 | <tr>
|
---|
107 | <td valign="top">failureproperty</td>
|
---|
108 | <td valign="top">The name of a property to set in the event of a failure
|
---|
109 | (errors are considered failures as well).</td>
|
---|
110 | <td align="center" valign="top">No.</td>
|
---|
111 | </tr>
|
---|
112 | <tr>
|
---|
113 | <td valign="top">filtertrace</td>
|
---|
114 | <td valign="top">Filter out Junit and Ant stack frames from error and failure stack traces.</td>
|
---|
115 | <td align="center" valign="top">No; default is <code>on</code>.</td>
|
---|
116 | </tr>
|
---|
117 | <tr>
|
---|
118 | <td valign="top">timeout</td>
|
---|
119 | <td valign="top">Cancel the individual tests if they don't finish
|
---|
120 | in the given time (measured in milliseconds). Ignored if
|
---|
121 | <code>fork</code> is disabled.</td>
|
---|
122 | <td align="center" valign="top">No</td>
|
---|
123 | </tr>
|
---|
124 | <tr>
|
---|
125 | <td valign="top">maxmemory</td>
|
---|
126 | <td valign="top">Maximum amount of memory to allocate to the forked VM.
|
---|
127 | Ignored if <code>fork</code> is disabled.</td>
|
---|
128 | <td align="center" valign="top">No</td>
|
---|
129 | </tr>
|
---|
130 | <tr>
|
---|
131 | <td valign="top">jvm</td>
|
---|
132 | <td valign="top">The command used to invoke the Java Virtual Machine,
|
---|
133 | default is 'java'. The command is resolved by
|
---|
134 | <code>java.lang.Runtime.exec()</code>.
|
---|
135 | Ignored if <code>fork</code> is disabled.</td>
|
---|
136 | <td align="center" valign="top">No; default is <code>java</code>.</td>
|
---|
137 | </tr>
|
---|
138 | <tr>
|
---|
139 | <td valign="top">dir</td>
|
---|
140 | <td valign="top">The directory in which to invoke the VM. Ignored if
|
---|
141 | <code>fork</code> is disabled.</td>
|
---|
142 | <td align="center" valign="top">No</td>
|
---|
143 | </tr>
|
---|
144 | <tr>
|
---|
145 | <td valign="top">newenvironment</td>
|
---|
146 | <td valign="top">Do not propagate the old environment when new
|
---|
147 | environment variables are specified. Ignored if <code>fork</code> is
|
---|
148 | disabled.</td>
|
---|
149 | <td align="center" valign="top">No; default is <code>false</code>.</td>
|
---|
150 | </tr>
|
---|
151 | <tr>
|
---|
152 | <td valign="top">includeantruntime</td>
|
---|
153 | <td valign="top">Implicitly add the Ant classes required to run
|
---|
154 | the tests and JUnit to the classpath in forked mode.
|
---|
155 | <b>Note:</b> Please read the <a
|
---|
156 | href="../../faq.html#junit-no-runtime-xml">Ant FAQ</a> if you
|
---|
157 | want to set this to <code>false</code> and use the XML formatter
|
---|
158 | at the same time.</td>
|
---|
159 | <td align="center" valign="top">No; default is <code>true</code>.</td>
|
---|
160 | </tr>
|
---|
161 | <tr>
|
---|
162 | <td valign="top">showoutput</td>
|
---|
163 | <td valign="top">Send any output generated by tests to Ant's
|
---|
164 | logging system as well as to the formatters. By default only the
|
---|
165 | formatters receive the output.</td>
|
---|
166 | <td align="center" valign="top">No</td>
|
---|
167 | </tr>
|
---|
168 | <tr>
|
---|
169 | <td valign="top">tempdir</td>
|
---|
170 | <td valign="top">Where Ant should place temporary files.
|
---|
171 | <em>Since Ant 1.6</em>.</td>
|
---|
172 | <td align="center" valign="top">No; default is the project's base
|
---|
173 | directory.</td>
|
---|
174 | </tr>
|
---|
175 | <tr>
|
---|
176 | <td valign="top">reloading</td>
|
---|
177 | <td valign="top">Whether or not a new classloader should be instantiated for each test case.<br/>
|
---|
178 | Ignore if <code>fork</code> is set to true.
|
---|
179 | <em>Since Ant 1.6</em>.</td>
|
---|
180 | <td align="center" valign="top">No; default is <code>true</code>.</td>
|
---|
181 | </tr>
|
---|
182 | </table>
|
---|
183 |
|
---|
184 | <p>By using the <code>errorproperty</code> and <code>failureproperty</code>
|
---|
185 | attributes, it is possible to
|
---|
186 | perform setup work (such as starting an external server), execute the test,
|
---|
187 | clean up, and still fail the build in the event of a failure.</p>
|
---|
188 |
|
---|
189 | <p>The <code>filtertrace</code> attribute condenses error and failure
|
---|
190 | stack traces before reporting them.
|
---|
191 | It works with both the plain and XML formatters. It filters out any lines
|
---|
192 | that begin with the following string patterns:<pre>
|
---|
193 | "junit.framework.TestCase"
|
---|
194 | "junit.framework.TestResult"
|
---|
195 | "junit.framework.TestSuite"
|
---|
196 | "junit.framework.Assert."
|
---|
197 | "junit.swingui.TestRunner"
|
---|
198 | "junit.awtui.TestRunner"
|
---|
199 | "junit.textui.TestRunner"
|
---|
200 | "java.lang.reflect.Method.invoke("
|
---|
201 | "org.apache.tools.ant."</pre></p>
|
---|
202 |
|
---|
203 | <a name="nested"></a><h3>Nested Elements</h3>
|
---|
204 |
|
---|
205 | <p>The <code><junit></code> task
|
---|
206 | supports a nested <code><classpath></code>
|
---|
207 | element that represents a <a href="../using.html#path">PATH like
|
---|
208 | structure</a>.</p>
|
---|
209 |
|
---|
210 | <h4>jvmarg</h4>
|
---|
211 |
|
---|
212 | <p>If <code>fork</code> is enabled, additional parameters may be passed to
|
---|
213 | the new VM via nested <code><jvmarg></code> elements. For example:</p>
|
---|
214 |
|
---|
215 | <pre>
|
---|
216 | <junit fork="yes">
|
---|
217 | <jvmarg value="-Djava.compiler=NONE"/>
|
---|
218 | ...
|
---|
219 | </junit>
|
---|
220 | </pre>
|
---|
221 |
|
---|
222 | <p>would run the test in a VM without JIT.</p>
|
---|
223 |
|
---|
224 | <p><code><jvmarg></code> allows all attributes described in <a
|
---|
225 | href="../using.html#arg">Command-line Arguments</a>.</p>
|
---|
226 |
|
---|
227 | <h4>sysproperty</h4>
|
---|
228 |
|
---|
229 | <p>Use nested <code><sysproperty></code> elements to specify system
|
---|
230 | properties required by the class. These properties will be made available
|
---|
231 | to the VM during the execution of the test (either ANT's VM or the forked VM,
|
---|
232 | if <code>fork</code> is enabled).
|
---|
233 | The attributes for this element are the same as for <a href="../CoreTasks/exec.html#env">environment variables</a>.</p>
|
---|
234 |
|
---|
235 | <pre>
|
---|
236 | <junit fork="no">
|
---|
237 | <sysproperty key="basedir" value="${basedir}"/>
|
---|
238 | ...
|
---|
239 | </junit>
|
---|
240 | </pre>
|
---|
241 |
|
---|
242 | <p>would run the test in ANT's VM and make the <code>basedir</code> property
|
---|
243 | available to the test.</p>
|
---|
244 |
|
---|
245 | <h4>syspropertyset</h4>
|
---|
246 |
|
---|
247 | <p>You can specify a set of properties to be used as system properties
|
---|
248 | with <a href="../CoreTypes/propertyset.html">syspropertyset</a>s.</p>
|
---|
249 |
|
---|
250 | <p><em>since Ant 1.6</em>.</p>
|
---|
251 |
|
---|
252 | <h4>env</h4>
|
---|
253 |
|
---|
254 | <p>It is possible to specify environment variables to pass to the
|
---|
255 | forked VM via nested <code><env></code> elements. For a description
|
---|
256 | of the <code><env></code> element's attributes, see the
|
---|
257 | description in the <a href="../CoreTasks/exec.html#env">exec</a> task.</p>
|
---|
258 |
|
---|
259 | <p>Settings will be ignored if <code>fork</code> is disabled.</p>
|
---|
260 |
|
---|
261 | <h4>bootclasspath</h4>
|
---|
262 |
|
---|
263 | <p>The location of bootstrap class files can be specified using this
|
---|
264 | <a href="../using.html#path">PATH like structure</a> - will be ignored
|
---|
265 | if <i>fork</i> is not <code>true</code> or the target VM doesn't
|
---|
266 | support it (i.e. Java 1.1).</p>
|
---|
267 |
|
---|
268 | <p><em>since Ant 1.6</em>.</p>
|
---|
269 |
|
---|
270 | <h4>permissions</h4>
|
---|
271 | <p>Security permissions can be revoked and granted during the execution of the
|
---|
272 | class via a nested <i>permissions</i> element. For more information please
|
---|
273 | see <a href="../CoreTypes/permissions.html">permissions</a></p>
|
---|
274 |
|
---|
275 | <p>Settings will be ignored if fork is enabled.</p>
|
---|
276 |
|
---|
277 | <p><em>since Ant 1.6</em>.</p>
|
---|
278 |
|
---|
279 | <h4>assertions</h4>
|
---|
280 |
|
---|
281 | <p>You can control enablement of Java 1.4 assertions with an
|
---|
282 | <a href="../CoreTypes/assertions.html"><tt><assertions></tt></a>
|
---|
283 | subelement.</p>
|
---|
284 |
|
---|
285 | <p>Assertion statements are currently ignored in non-forked mode.</p>
|
---|
286 |
|
---|
287 | <p><em>since Ant 1.6.</em></p>
|
---|
288 |
|
---|
289 | <h4>formatter</h4>
|
---|
290 |
|
---|
291 | <p>The results of the tests can be printed in different
|
---|
292 | formats. Output will always be sent to a file, unless you set the
|
---|
293 | <code>usefile</code> attribute to <code>false</code>.
|
---|
294 | The name of the file is determined by the
|
---|
295 | name of the test and can be set by the <code>outfile</code> attribute
|
---|
296 | of <code><test></code>.</p>
|
---|
297 |
|
---|
298 | <p>There are three predefined formatters - one prints the test results
|
---|
299 | in XML format, the other emits plain text. The formatter named
|
---|
300 | <code>brief</code> will only print detailed information for testcases
|
---|
301 | that failed, while <code>plain</code> gives a little statistics line
|
---|
302 | for all test cases. Custom formatters that need to implement
|
---|
303 | <code>org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter</code>
|
---|
304 | can be specified.</p>
|
---|
305 |
|
---|
306 | <p>If you use the XML formatter, it may not include the same output
|
---|
307 | that your tests have written as some characters are illegal in XML
|
---|
308 | documents and will be dropped.</p>
|
---|
309 |
|
---|
310 | <p><b>Note:</b> Please read the <a
|
---|
311 | href="../../faq.html#junit-no-runtime-xml">Ant FAQ</a> if you want to
|
---|
312 | set the fork attribute to <code>true</code>, the includeAntRuntime
|
---|
313 | attribute to <code>false</code> and use the XML formatter at the same
|
---|
314 | time.</p>
|
---|
315 |
|
---|
316 | <table border="1" cellpadding="2" cellspacing="0">
|
---|
317 | <tr>
|
---|
318 | <td width="12%" valign="top"><b>Attribute</b></td>
|
---|
319 | <td width="78%" valign="top"><b>Description</b></td>
|
---|
320 | <td width="10%" valign="top"><b>Required</b></td>
|
---|
321 | </tr>
|
---|
322 | <tr>
|
---|
323 | <td valign="top">type</td>
|
---|
324 | <td valign="top">Use a predefined formatter (either
|
---|
325 | <code>xml</code>, <code>plain</code>, or <code>brief</code>).</td>
|
---|
326 | <td align="center" rowspan="2">Exactly one of these.</td>
|
---|
327 | </tr>
|
---|
328 | <tr>
|
---|
329 | <td valign="top">classname</td>
|
---|
330 | <td valign="top">Name of a custom formatter class.</td>
|
---|
331 | </tr>
|
---|
332 | <tr>
|
---|
333 | <td valign="top">extension</td>
|
---|
334 | <td valign="top">Extension to append to the output filename.</td>
|
---|
335 | <td align="center">Yes, if <code>classname</code> has been used.</td>
|
---|
336 | </tr>
|
---|
337 | <tr>
|
---|
338 | <td valign="top">usefile</td>
|
---|
339 | <td valign="top">Boolean that determines whether output should be
|
---|
340 | sent to a file.</td>
|
---|
341 | <td align="center">No; default is <code>true</code>.</td>
|
---|
342 | </tr>
|
---|
343 | <tr>
|
---|
344 | <td valign="top">if</td>
|
---|
345 | <td valign="top">Only use formatter if the named property is set.</td>
|
---|
346 | <td align="center">No; default is <code>true</code>.</td>
|
---|
347 | </tr>
|
---|
348 | <tr>
|
---|
349 | <td valign="top">unless</td>
|
---|
350 | <td valign="top">Only use formatter if the named property is <b>not</b> set.</td>
|
---|
351 | <td align="center">No; default is <code>true</code>.</td>
|
---|
352 | </tr>
|
---|
353 | </table>
|
---|
354 |
|
---|
355 | <h4>test</h4>
|
---|
356 |
|
---|
357 | <p>Defines a single test class.</p>
|
---|
358 |
|
---|
359 | <table border="1" cellpadding="2" cellspacing="0">
|
---|
360 | <tr>
|
---|
361 | <td width="12%" valign="top"><b>Attribute</b></td>
|
---|
362 | <td width="78%" valign="top"><b>Description</b></td>
|
---|
363 | <td width="10%" valign="top"><b>Required</b></td>
|
---|
364 | </tr>
|
---|
365 | <tr>
|
---|
366 | <td valign="top">name</td>
|
---|
367 | <td valign="top">Name of the test class.</td>
|
---|
368 | <td align="center">Yes</td>
|
---|
369 | </tr>
|
---|
370 | <tr>
|
---|
371 | <td valign="top">fork</td>
|
---|
372 | <td valign="top">Run the tests in a separate VM.
|
---|
373 | Overrides value set in <code><junit></code>.</td>
|
---|
374 | <td align="center" valign="top">No</td>
|
---|
375 | </tr>
|
---|
376 | <tr>
|
---|
377 | <td valign="top">haltonerror</td>
|
---|
378 | <td valign="top">Stop the build process if an error occurs during the test
|
---|
379 | run. Overrides value set in <code><junit></code>.</td>
|
---|
380 | <td align="center" valign="top">No</td>
|
---|
381 | </tr>
|
---|
382 | <tr>
|
---|
383 | <td valign="top">errorproperty</td>
|
---|
384 | <td valign="top">The name of a property to set in the event of an error.
|
---|
385 | Overrides value set in <code><junit></code>.</td>
|
---|
386 | <td align="center" valign="top">No</td>
|
---|
387 | </tr>
|
---|
388 | <tr>
|
---|
389 | <td valign="top">haltonfailure</td>
|
---|
390 | <td valign="top">Stop the build process if a test fails (errors are
|
---|
391 | considered failures as well). Overrides value set in
|
---|
392 | <code><junit></code>.</td>
|
---|
393 | <td align="center" valign="top">No</td>
|
---|
394 | </tr>
|
---|
395 | <tr>
|
---|
396 | <td valign="top">failureproperty</td>
|
---|
397 | <td valign="top">The name of a property to set in the event of a failure
|
---|
398 | (errors are considered failures as well). Overrides value set in
|
---|
399 | <code><junit></code>.</td>
|
---|
400 | <td align="center" valign="top">No</td>
|
---|
401 | </tr>
|
---|
402 | <tr>
|
---|
403 | <td valign="top">filtertrace</td>
|
---|
404 | <td valign="top">Filter out Junit and Ant stack frames from error and failure stack
|
---|
405 | traces. Overrides value set in <code><junit></code>.</td>
|
---|
406 | <td align="center" valign="top">No; default is <code>on</code>.</td>
|
---|
407 | </tr>
|
---|
408 | <tr>
|
---|
409 | <td valign="top">todir</td>
|
---|
410 | <td valign="top">Directory to write the reports to.</td>
|
---|
411 | <td align="center" valign="top">No; default is the current directory.</td>
|
---|
412 | </tr>
|
---|
413 | <tr>
|
---|
414 | <td valign="top">outfile</td>
|
---|
415 | <td valign="top">Base name of the test result. The full filename is
|
---|
416 | determined by this attribute and the extension of
|
---|
417 | <code>formatter</code>.</td>
|
---|
418 | <td align="center" valign="top">No; default is
|
---|
419 | <code>TEST-</code><em>name</em>, where <em>name</em> is the name of
|
---|
420 | the test specified in the <code>name</code> attribute.</td>
|
---|
421 | </tr>
|
---|
422 | <tr>
|
---|
423 | <td valign="top">if</td>
|
---|
424 | <td valign="top">Only run test if the named property is set.</td>
|
---|
425 | <td align="center" valign="top">No</td>
|
---|
426 | </tr>
|
---|
427 | <tr>
|
---|
428 | <td valign="top">unless</td>
|
---|
429 | <td valign="top">Only run test if the named property is <b>not</b> set.</td>
|
---|
430 | <td align="center" valign="top">No</td>
|
---|
431 | </tr>
|
---|
432 | </table>
|
---|
433 |
|
---|
434 | <p>Tests can define their own formatters via nested
|
---|
435 | <code><formatter></code> elements.</p>
|
---|
436 |
|
---|
437 | <h4>batchtest</h4>
|
---|
438 |
|
---|
439 | <p>Define a number of tests based on pattern matching.</p>
|
---|
440 |
|
---|
441 | <p><code>batchtest</code> collects the included files from any number
|
---|
442 | of nested <a
|
---|
443 | href="../CoreTypes/fileset.html"><code><fileset></code></a>s. It then
|
---|
444 | generates a test class name for each file that ends in
|
---|
445 | <code>.java</code> or <code>.class</code>.</p>
|
---|
446 |
|
---|
447 | <table border="1" cellpadding="2" cellspacing="0">
|
---|
448 | <tr>
|
---|
449 | <td width="12%" valign="top"><b>Attribute</b></td>
|
---|
450 | <td width="78%" valign="top"><b>Description</b></td>
|
---|
451 | <td width="10%" valign="top"><b>Required</b></td>
|
---|
452 | </tr>
|
---|
453 | <tr>
|
---|
454 | <td valign="top">fork</td>
|
---|
455 | <td valign="top">Run the tests in a separate VM.
|
---|
456 | Overrides value set in <code><junit></code>.</td>
|
---|
457 | <td align="center" valign="top">No</td>
|
---|
458 | </tr>
|
---|
459 | <tr>
|
---|
460 | <td valign="top">haltonerror</td>
|
---|
461 | <td valign="top">Stop the build process if an error occurs during the test
|
---|
462 | run. Overrides value set in <code><junit></code>.</td>
|
---|
463 | <td align="center" valign="top">No</td>
|
---|
464 | </tr>
|
---|
465 | <tr>
|
---|
466 | <td valign="top">errorproperty</td>
|
---|
467 | <td valign="top">The name of a property to set in the event of an error.
|
---|
468 | Overrides value set in <code><junit></code>.</td>
|
---|
469 | <td align="center" valign="top">No</td>
|
---|
470 | </tr>
|
---|
471 | <tr>
|
---|
472 | <td valign="top">haltonfailure</td>
|
---|
473 | <td valign="top">Stop the build process if a test fails (errors are
|
---|
474 | considered failures as well). Overrides value set in
|
---|
475 | <code><junit></code>.</td>
|
---|
476 | <td align="center" valign="top">No</td>
|
---|
477 | </tr>
|
---|
478 | <tr>
|
---|
479 | <td valign="top">failureproperty</td>
|
---|
480 | <td valign="top">The name of a property to set in the event of a failure
|
---|
481 | (errors are considered failures as well). Overrides value set in
|
---|
482 | <code><junit></code></td>
|
---|
483 | <td align="center" valign="top">No</td>
|
---|
484 | </tr>
|
---|
485 | <tr>
|
---|
486 | <td valign="top">filtertrace</td>
|
---|
487 | <td valign="top">Filter out Junit and Ant stack frames from error and failure stack
|
---|
488 | traces. Overrides value set in <code><junit></code>.</td>
|
---|
489 | <td align="center" valign="top">No; default is <code>on</code>.</td>
|
---|
490 | </tr>
|
---|
491 | <tr>
|
---|
492 | <td valign="top">todir</td>
|
---|
493 | <td valign="top">Directory to write the reports to.</td>
|
---|
494 | <td align="center" valign="top">No; default is the current directory.</td>
|
---|
495 | </tr>
|
---|
496 | <tr>
|
---|
497 | <td valign="top">if</td>
|
---|
498 | <td valign="top">Only run tests if the named property is set.</td>
|
---|
499 | <td align="center" valign="top">No</td>
|
---|
500 | </tr>
|
---|
501 | <tr>
|
---|
502 | <td valign="top">unless</td>
|
---|
503 | <td valign="top">Only run tests if the named property is <strong>not</strong> set.</td>
|
---|
504 | <td align="center" valign="top">No</td>
|
---|
505 | </tr>
|
---|
506 | </table>
|
---|
507 |
|
---|
508 | <p>Batchtests can define their own formatters via nested
|
---|
509 | <code><formatter></code> elements.</p>
|
---|
510 |
|
---|
511 | <h3>Examples</h3>
|
---|
512 |
|
---|
513 | <pre>
|
---|
514 | <junit>
|
---|
515 | <test name="my.test.TestCase"/>
|
---|
516 | </junit>
|
---|
517 | </pre>
|
---|
518 |
|
---|
519 | <p>Runs the test defined in <code>my.test.TestCase</code> in the same
|
---|
520 | VM. No output will be generated unless the test fails.</p>
|
---|
521 |
|
---|
522 | <pre>
|
---|
523 | <junit printsummary="yes" fork="yes" haltonfailure="yes">
|
---|
524 | <formatter type="plain"/>
|
---|
525 | <test name="my.test.TestCase"/>
|
---|
526 | </junit>
|
---|
527 | </pre>
|
---|
528 |
|
---|
529 | <p>Runs the test defined in <code>my.test.TestCase</code> in a
|
---|
530 | separate VM. At the end of the test, a one-line summary will be
|
---|
531 | printed. A detailed report of the test can be found in
|
---|
532 | <code>TEST-my.test.TestCase.txt</code>. The build process will be
|
---|
533 | stopped if the test fails.</p>
|
---|
534 |
|
---|
535 | <pre>
|
---|
536 | <junit printsummary="yes" haltonfailure="yes">
|
---|
537 | <classpath>
|
---|
538 | <pathelement location="${build.tests}"/>
|
---|
539 | <pathelement path="${java.class.path}"/>
|
---|
540 | </classpath>
|
---|
541 |
|
---|
542 | <formatter type="plain"/>
|
---|
543 |
|
---|
544 | <test name="my.test.TestCase" haltonfailure="no" outfile="result">
|
---|
545 | <formatter type="xml"/>
|
---|
546 | </test>
|
---|
547 |
|
---|
548 | <batchtest fork="yes" todir="${reports.tests}">
|
---|
549 | <fileset dir="${src.tests}">
|
---|
550 | <include name="**/*Test*.java"/>
|
---|
551 | <exclude name="**/AllTests.java"/>
|
---|
552 | </fileset>
|
---|
553 | </batchtest>
|
---|
554 | </junit>
|
---|
555 | </pre>
|
---|
556 |
|
---|
557 | <p>Runs <code>my.test.TestCase</code> in the same VM, ignoring the
|
---|
558 | given CLASSPATH; only a warning is printed if this test fails. In
|
---|
559 | addition to the plain text test results, for this test a XML result
|
---|
560 | will be output to <code>result.xml</code>.
|
---|
561 | Then, for each matching file in the directory defined for
|
---|
562 | <code>${src.tests}</code> a
|
---|
563 | test is run in a separate VM. If a test fails, the build process is
|
---|
564 | aborted. Results are collected in files named
|
---|
565 | <code>TEST-</code><em>name</em><code>.txt</code> and written to
|
---|
566 | <code>${reports.tests}</code>.</p>
|
---|
567 |
|
---|
568 | <hr>
|
---|
569 | <p align="center">Copyright © 2000-2004 The Apache Software Foundation. All rights
|
---|
570 | Reserved.</p>
|
---|
571 | </body>
|
---|
572 | </html>
|
---|