Debian Codegraph @

manual/Tasks/junitlauncher.html

raw
1 <!DOCTYPE html>
2 <!--
3 Licensed to the Apache Software Foundation (ASF) under one or more
4 contributor license agreements. See the NOTICE file distributed with
5 this work for additional information regarding copyright ownership.
6 The ASF licenses this file to You under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with
8 the License. You may obtain a copy of the License at
9
10 https://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 -->
18 <html lang="en">
19 <head>
20 <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
21 <title>JUnitLauncher Task</title>
22 </head>
23 <body>
24
25 <h2 id="junitlauncher">JUnitLauncher</h2>
26 <h3>Description</h3>
27
28 <p>
29 This task allows tests to be launched and run using the JUnit 5 framework.
30 </p>
31 <p>
32 JUnit 5 introduced a newer set of APIs to write and launch tests. It also introduced the concept
33 of test engines. Test engines decide which classes are considered as testcases and how they are
34 executed. JUnit 5 supports running tests that have been written using JUnit 4 constructs as well
35 as tests that have been written using JUnit 5 constructs. For more details about JUnit 5
36 itself, please refer to the JUnit 5 project's documentation
37 at <a href="https://junit.org/junit5/">https://junit.org/junit5/</a>.
38 </p>
39 <p>
40 The goal of this <code>junitlauncher</code> task is to allow launching the JUnit 5 test launcher
41 and building the test requests so that the selected tests can then be parsed and executed by the
42 test engine(s) supported by JUnit 5. This task in itself does <i>not</i> understand what a test
43 case is nor does it execute the tests itself.
44 </p>
45 <p>
46 This task captures testoutput and configuration data inside of
47 the <a href="../running.html#tmpdir">temporary directory</a>.
48 </p>
49 <p>
50 <strong>Note</strong>: This task depends on external libraries not included in the Apache Ant
51 distribution. See <a href="../install.html#librarydependencies">Library Dependencies</a> for
52 more information.
53 </p>
54 <p>
55 <strong>Note</strong>: You must have the necessary JUnit 5 libraries in the classpath of the
56 tests. At the time of writing this documentation, the list of JUnit 5 platform libraries that
57 are necessary to run the tests are:
58 </p>
59
60 <ul id="junit-platform-libraries">
61 <li>
62 <samp>junit-platform-commons.jar</samp>
63 </li>
64 <li>
65 <samp>junit-platform-engine.jar</samp>
66 </li>
67 <li>
68 <samp>junit-platform-launcher.jar</samp>
69 </li>
70 <li>
71 <samp>opentest4j.jar</samp>
72 </li>
73 </ul>
74
75 <p>
76 Depending on the test engine(s) that you want to use in your tests, you will further need the
77 following libraries in the classpath
78 </p>
79
80 <p id="junit-vintage-engine-libraries">
81 For <q>junit-vintage</q> engine:
82 </p>
83
84 <ul>
85 <li>
86 <samp>junit-vintage-engine.jar</samp>
87 </li>
88 <li>
89 <samp>junit.jar</samp> (JUnit 4.x version)
90 </li>
91 </ul>
92
93 <p id="junit-jupiter-engine-libraries">
94 For <q>junit-jupiter</q> engine:
95 </p>
96
97 <ul>
98 <li>
99 <samp>junit-jupiter-api.jar</samp>
100 </li>
101 <li>
102 <samp>junit-jupiter-engine.jar</samp>
103 </li>
104 </ul>
105
106 <p>
107 To have these in the test classpath, you can follow <em>either</em> of the following approaches:
108 </p>
109
110 <ul id="setup">
111 <li id="setup-recommended"><b>Recommended approach since Ant 1.10.6</b>: Place the <samp>ant-junitlauncher.jar</samp> in <samp>ANT_HOME/lib</samp> directory
112 and use the nested <code>&lt;classpath&gt;</code> element to specify the location of the
113 the rest of the JUnit specific jars (noted above). Please read the
114 <a href=#nested-classpath>using classpath element</a> section for more details.</li>
115
116 <li>OR Put all these relevant jars along with the <samp>ant-junitlauncher.jar</samp>
117 in <samp>ANT_HOME/lib</samp> directory</li>
118
119 <li>OR Put <samp>ant-junitlauncher.jar</samp> in the <samp>ANT_HOME/lib</samp> directory and
120 include all other relevant jars in the classpath by passing them as a <kbd>-lib</kbd>
121 option, while invoking Ant</li>
122 </ul>
123
124 <p>
125 Tests are defined by nested elements like <code>test</code>, <code>testclasses</code> tags
126 (see <a href="#nested">nested elements</a>).
127 </p>
128
129 <h3>Parameters</h3>
130 <table class="attr">
131 <tr>
132 <th scope="col">Attribute</th>
133 <th scope="col">Description</th>
134 <th scope="col">Required</th>
135 </tr>
136 <tr>
137 <td>includeTags</td>
138 <td>A comma separated list of <a href="https://junit.org/junit5/docs/current/user-guide/#writing-tests-annotations">JUnit 5 tags</a>, describing the tests to include.
139 <p><em>Since Ant 1.10.7</em></p>
140 </td>
141 <td>No</td>
142 </tr>
143 <tr>
144 <td>excludeTags</td>
145 <td>A comma separated list of <a href="https://junit.org/junit5/docs/current/user-guide/#writing-tests-annotations">JUnit 5 tags</a>, describing the tests to exclude.
146 <p><em>Since Ant 1.10.7</em></p>
147 </td>
148 <td>No</td>
149 </tr>
150 <tr>
151 <td>haltOnFailure</td>
152 <td>A value of <q>true</q> implies that build has to stop if any failure occurs in any of
153 the tests. JUnit 4+ classifies failures as both assertion failures as well as exceptions
154 that get thrown during test execution. As such, this task too considers both these cases
155 as failures and doesn't distinguish one from another.
156 </td>
157 <td>No; default is <q>false</q></td>
158 </tr>
159 <tr>
160 <td>failureProperty</td>
161 <td>The name of a property to set in the event of a failure
162 (exceptions in tests are considered failures as well).
163 </td>
164 <td>No</td>
165 </tr>
166 <tr>
167 <td>printSummary</td>
168 <td>If the value is set to <code>true</code> then this task, upon completion of the test execution,
169 prints the summary of the execution to <code>System.out</code>. Starting Ant 1.10.10, unlike
170 in previous versions, this task itself generates the summary instead of using the one generated
171 by the JUnit 5 platform.
172 </td>
173 <td>No; defaults to <code>false</code></td>
174 </tr>
175 </table>
176
177 <h3 id="nested">Nested Elements</h3>
178
179 <h4 id="nested-classpath">classpath</h4>
180 <p>
181 The nested <code>&lt;classpath&gt;</code> element that represents
182 a <a href="../using.html#path">PATH like structure</a> can be used to configure the task to use
183 this classpath for finding and running the tests. This classpath will be used for:
184 </p>
185 <ul>
186 <li>Finding the test classes to execute</li>
187 <li>Finding test engines that run the tests</li>
188 <li>If <a href="#setup-recommended">configured to do so</a>, finding all necessary JUnit libraries</li>
189 </ul>
190 <p>
191 If the <code>classpath</code> element isn't configured for the task, then the classpath of Ant
192 itself will be used for finding the test classes and the JUnit libraries.
193 </p>
194
195 <p>
196 Below is an example of setting up the classpath to include the Jupiter test engine and
197 the JUnit platform libraries during the execution of the tests.
198 </p>
199 <pre>
200 &lt;project&gt;
201
202 &lt;property name="output.dir" value="${basedir}/build"/&gt;
203 &lt;property name="src.test.dir" value="${basedir}/src/test"/&gt;
204 &lt;property name="build.classes.dir" value="${output.dir}/classes"/&gt;
205
206 &lt;target name="init"&gt;
207 &lt;mkdir dir="${output.dir}"/&gt;
208 &lt;/target&gt;
209
210 &lt;path id="junit.platform.libs.classpath"&gt;
211 &lt;fileset dir="${basedir}/src/lib/junit-platform/"/&gt;
212 &lt;/path&gt;
213
214 &lt;path id="junit.engine.jupiter.classpath"&gt;
215 &lt;fileset dir="${basedir}/src/lib/jupiter/"/&gt;
216 &lt;/path&gt;
217
218 &lt;target name="compile-test" depends="init"&gt;
219 &lt;mkdir dir="${build.classes.dir}"/&gt;
220 &lt;javac srcdir="${src.test.dir}"
221 destdir="${build.classes.dir}"&gt;
222 &lt;!-- our tests only need JUnit Jupiter engine
223 libraries in our compile classpath for the tests --&gt;
224 &lt;classpath refid="junit.engine.jupiter.classpath"/&gt;
225 &lt;/javac&gt;
226 &lt;/target&gt;
227
228 &lt;target name="test" depends="compile-test"&gt;
229 &lt;junitlauncher&gt;
230 &lt;!-- include the JUnit platform related libraries
231 required to run the tests --&gt;
232 &lt;classpath refid="junit.platform.libs.classpath"/&gt;
233
234 &lt;!-- include the JUnit Jupiter engine libraries --&gt;
235 &lt;classpath refid="junit.engine.jupiter.classpath"/&gt;
236
237 &lt;classpath&gt;
238 &lt;!-- the test classes themselves --&gt;
239 &lt;pathelement location="${build.classes.dir}"/&gt;
240 &lt;/classpath&gt;
241 &lt;testclasses outputdir="${output.dir}"&gt;
242 &lt;fileset dir="${build.classes.dir}"/&gt;
243 &lt;listener type="legacy-brief" sendSysOut="true"/&gt;
244 &lt;listener type="legacy-xml" sendSysErr="true" sendSysOut="true"/&gt;
245
246 &lt;/testclasses&gt;
247 &lt;/junitlauncher&gt;
248 &lt;/target&gt;
249 &lt;/project&gt;
250 </pre>
251 <p>
252 In the example above,
253 </p>
254 <ul>
255 <li>The <code>src/lib/jupiter</code> directory is expected to contain
256 the Jupiter test engine related jars (which have been
257 <a href="#junit-jupiter-engine-libraries">listed in an earlier section of this
258 document</a>).</li>
259 <li>The <code>src/lib/junit-platform</code> directory is expected to
260 contain the JUnit platform jars (which have been
261 <a href="#junit-platform-libraries">listed in an earlier section of this
262 document</a>)</li>
263 </ul>
264 <p>
265 In the <code>test</code> target we use the <code>classpath</code> nested element
266 to point to the <code>junit.engine.jupiter.classpath</code> and <code>junit.platform.libs.classpath</code>
267 containing those jars.
268 In this <code>test</code> target we also use another <code>classpath</code> element to point to
269 the location containing our test classes. If required, all these classpaths can be combined
270 into one.
271 </p>
272
273 <h4>listener</h4>
274
275 <p>
276 The <code>junitlauncher</code> task can be configured with <code>listener</code>(s) to listen to
277 test execution events (such as a test execution starting, completing etc...). The listener is
278 expected to be a class which implements
279 the <code class="code">org.junit.platform.launcher.TestExecutionListener</code>.
280 This <code class="code">TestExecutionListener</code> interface is an API exposed by the JUnit 5
281 platform APIs and isn't specific to Ant. As such, you can use any existing implementation
282 of <code class="code">TestExecutionListener</code> in this task.
283 </p>
284
285 <h5>Test result formatter</h5>
286 <p>
287 <code>junitlauncher</code> provides a way where the test execution results can be formatted and
288 presented in a way that's customizable. The task allows for configuring test result formatters,
289 through the use of <code>listener</code> element. As noted previously, the <code>listener</code>
290 element expects the listener to implement
291 the <code class="code">org.junit.platform.launcher.TestExecutionListener</code>
292 interface. Typically, result formatters need a bit more configuration details to be fed to them,
293 during the test execution&mdash;details like where to write out the formatted result. Any such
294 listener can optionally implement
295 the <code class="code">org.apache.tools.ant.taskdefs.optional.junitlauncher.TestResultFormatter</code>
296 interface. This interface is specific to Ant <code>junitlauncher</code> task and it extends
297 the <code class="code">org.junit.platform.launcher.TestExecutionListener</code> interface
298 </p>
299 <p>
300 The <code>junitlauncher</code> task comes with the following pre-defined test result formatter
301 types:
302 </p>
303 <ul>
304 <li>
305 <q>legacy-plain</q> : This formatter prints a short statistics line for all test
306 cases.
307 </li>
308 <li>
309 <q>legacy-brief</q> : This formatter prints information for tests that failed or were
310 skipped.
311 </li>
312 <li>
313 <q>legacy-xml</q> : This formatter prints statistics for the tests in XML format.
314 </li>
315 </ul>
316 <p>
317 <strong>Note</strong>: Each of these formatters named <q>legacy</q> try to format the results
318 similar to what the <code>junit</code> task's formatters used to do. Furthermore,
319 the <q>legacy-xml</q> formatter generates the XML to comply with the same schema that
320 the <code>junit</code> task's XML formatter used to follow. As a result, the XML generated by
321 this formatter, can be used as-is by the <code>junitreport</code> task.
322 </p>
323 <p>
324 The <code>listener</code> element supports the following attributes:
325 </p>
326 <table class="attr">
327 <tr>
328 <th scope="col">Attribute</th>
329 <th scope="col">Description</th>
330 <th scope="col">Required</th>
331 </tr>
332 <tr>
333 <td>type</td>
334 <td>Use a predefined formatter (either <q>legacy-xml</q>, <q>legacy-plain</q>
335 or <q>legacy-brief</q>).</td>
336 <td rowspan="2">Exactly one of these</td>
337 </tr>
338 <tr>
339 <td>classname</td>
340 <td class="left">Name of a listener class which
341 implements <code>org.junit.platform.launcher.TestExecutionListener</code> or
342 the <code>org.apache.tools.ant.taskdefs.optional.junitlauncher.TestResultFormatter</code>
343 interface
344 </td>
345 </tr>
346 <tr>
347 <td>resultFile</td>
348 <td>
349 The file name to which the formatted result needs to be written to. This attribute is
350 only relevant when the listener class implements
351 the <code>org.apache.tools.ant.taskdefs.optional.junitlauncher.TestResultFormatter</code>
352 interface.
353 <p>
354 If no value is specified for this attribute and the listener implements
355 the <code>org.apache.tools.ant.taskdefs.optional.junitlauncher.TestResultFormatter</code>
356 then the file name will be defaulted to and will be of the
357 form <code>TEST-<i>testname</i>.<i>extension</i></code>
358 (ex: <samp>TEST-org.myapp.SomeTest.xml</samp> for the <q>legacy-xml</q> type
359 formatter)
360 </p>
361 <p>
362 This file is considered relative to the <code>outputDir</code> configured on the listener.
363 If no <code>outputDir</code> is set on the listener, then the file is considered relative to the
364 <code>outputDir</code> of the test in context of which this listener is being run.
365 </p>
366 </td>
367 <td>No</td>
368 </tr>
369 <tr>
370 <td>extension</td>
371 <td>Extension to append to the output filename.
372 <p><em>Since Ant 1.10.13</em></p>
373 </td>
374 <td>No; defaults to <q>xml</q> for the <q>legacy-xml</q> formatter and to <q>txt</q> for the rest</td>
375 </tr>
376 <tr>
377 <td>outputDir</td>
378 <td>Directory into which to create the output of the listener.
379 <p><em>Since Ant 1.10.6</em></p>
380 </td>
381 <td>No</td>
382 </tr>
383 <tr>
384 <td>sendSysOut</td>
385 <td>If set to <q>true</q> then the listener will be passed the <code>stdout</code> content
386 generated by the test(s). This attribute is relevant only if the listener class
387 implements
388 the <code>org.apache.tools.ant.taskdefs.optional.junitlauncher.TestResultFormatter</code>
389 interface.</td>
390 <td>No; defaults to <q>false</q></td>
391 </tr>
392 <tr>
393 <td>sendSysErr</td>
394 <td>If set to <q>true</q> then the listener will be passed the <code>stderr</code> content
395 generated by the test(s). This attribute is relevant only if the listener class
396 implements
397 the <code>org.apache.tools.ant.taskdefs.optional.junitlauncher.TestResultFormatter</code>
398 interface.</td>
399 <td>No; defaults to <q>false</q></td>
400 </tr>
401 <tr>
402 <td>if</td>
403 <td>Only use this listener <a href="../properties.html#if+unless">if the named property is
404 set</a>.</td>
405 <td>No</td>
406 </tr>
407 <tr>
408 <td>unless</td>
409 <td>Only use this listener <a href="../properties.html#if+unless">if the named property
410 is <strong>not</strong> set</a>.</td>
411 <td>No</td>
412 </tr>
413 <tr>
414 <td>useLegacyReportingName</td>
415 <td>Set to true, if the test identifiers reported by this listener should use legacy (JUnit4
416 style) names. Else set to false.
417 <p><em>Since Ant 1.10.10</em></p>
418 </td>
419 <td>No; defaults to <q>true</q></td>
420 </tr>
421 </table>
422
423 <h4>test</h4>
424
425 <p>Defines a single test class.</p>
426
427 <table class="attr">
428 <tr>
429 <th scope="col">Attribute</th>
430 <th scope="col">Description</th>
431 <th scope="col">Required</th>
432 </tr>
433 <tr>
434 <td>name</td>
435 <td>Fully qualified name of the test class.</td>
436 <td>Yes</td>
437 </tr>
438 <tr>
439 <td>methods</td>
440 <td>Comma-separated list of names of test case methods to execute. If this is specified,
441 then only these test methods from the test class will be executed.</td>
442 <td>No</td>
443 </tr>
444 <tr>
445 <td>haltOnFailure</td>
446 <td>Stop the build process if a failure occurs during the test run (exceptions are
447 considered as failures too). Overrides value set on <code>junitlauncher</code>
448 element.</td>
449 <td>No</td>
450 </tr>
451 <tr>
452 <td>failureProperty</td>
453 <td>The name of a property to set in the event of a failure (exceptions are considered
454 failures as well). Overrides value set on <code>junitlauncher</code> element.</td>
455 <td>No</td>
456 </tr>
457 <tr>
458 <td>outputDir</td>
459 <td>Directory to write the reports to.</td>
460 <td>No; default is the base directory of the project.</td>
461 </tr>
462 <tr>
463 <td>if</td>
464 <td>Only run this test <a href="../properties.html#if+unless">if the named property is
465 set</a>.</td>
466 <td>No</td>
467 </tr>
468 <tr>
469 <td>unless</td>
470 <td>Only run this test <a href="../properties.html#if+unless">if the named property
471 is <strong>not</strong> set</a>.</td>
472 <td>No</td>
473 </tr>
474 <tr>
475 <td>includeEngines</td>
476 <td>A comma separated set of test engine ids. If specified, only these test engine(s)
477 will be used for running the tests.
478 <br/>
479 For example: <code>includeEngines="junit-jupiter"</code> will only use the Jupiter
480 test engine for execution of the tests and will ignore any other engines that might
481 have been found in the classpath.
482 </td>
483 <td>No</td>
484 </tr>
485 <tr>
486 <td>excludeEngines</td>
487 <td>A comma separated set of test engine ids. If specified, these test engine(s)
488 will be excluded when running the tests.
489 <br/>
490 For example: <code>excludeEngines="junit-vintage"</code> will exclude the vintage
491 test engine during execution of the tests and will use any other engines that might
492 have been found in the classpath.
493 </td>
494 <td>No</td>
495 </tr>
496 </table>
497
498 <p>
499 Tests can define their own listeners via nested <code>listener</code> elements.
500 </p>
501
502 <p>
503 The <a href="#fork">fork</a> nested element can be used to run the test in a newly forked
504 JVM.
505 </p>
506
507 <h4>testclasses</h4>
508
509 <p>Define a number of tests based on pattern matching.</p>
510
511 <p>
512 <code>testclasses</code> collects the included <a href="../Types/resources.html">resources</a>
513 from any number of nested <a href="../Types/resources.html#collection">Resource
514 Collection</a>s. It then selects each resource whose name ends in <code>.class</code>. These
515 classes are then passed on to the JUnit 5 platform for it to decide and run them as tests.
516 </p>
517
518 <table class="attr">
519 <tr>
520 <th scope="col">Attribute</th>
521 <th scope="col">Description</th>
522 <th scope="col">Required</th>
523 </tr>
524 <tr>
525 <td>haltOnFailure</td>
526 <td>Stop the build process if a failure occurs during the test run (exceptions are
527 considered as failures too). Overrides value set on <code>junitlauncher</code>
528 element.</td>
529 <td>No</td>
530 </tr>
531 <tr>
532 <td>failureProperty</td>
533 <td>The name of a property to set in the event of a failure (exceptions are considered
534 failures as well). Overrides value set on <code>junitlauncher</code> element.</td>
535 <td>No</td>
536 </tr>
537 <tr>
538 <td>outputDir</td>
539 <td>Directory to write the reports to.</td>
540 <td>No; default is the base directory of the project.</td>
541 </tr>
542 <tr>
543 <td>if</td>
544 <td>Only run the tests <a href="../properties.html#if+unless">if the named property is
545 set</a>.</td>
546 <td>No</td>
547 </tr>
548 <tr>
549 <td>unless</td>
550 <td>Only run the tests <a href="../properties.html#if+unless">if the named property
551 is <strong>not</strong> set</a>.</td>
552 <td>No</td>
553 </tr>
554 <tr>
555 <td>includeEngines</td>
556 <td>A comma separated set of test engine ids. If specified, only these test engine(s)
557 will be used for running the tests.
558 <br/>
559 For example: <code>includeEngines="junit-jupiter"</code> will only use the Jupiter
560 test engine for execution of the tests and will ignore any other engines that might
561 have been found in the classpath.
562 </td>
563 <td>No</td>
564 </tr>
565 <tr>
566 <td>excludeEngines</td>
567 <td>A comma separated set of test engine ids. If specified, these test engine(s)
568 will be excluded when running the tests.
569 <br/>
570 For example: <code>excludeEngines="junit-vintage"</code> will exclude the vintage
571 test engine during execution of the tests and will use any other engines that might
572 have been found in the classpath.
573 </td>
574 <td>No</td>
575 </tr>
576 </table>
577
578 <p>
579 <code>testclasses</code> can define their own listeners via nested <code>listener</code>
580 elements.
581 </p>
582
583 <p>
584 The <a href="#fork">fork</a> nested element can be used to run the tests in a newly forked
585 JVM. All tests that are part of this <code>testclasses</code> element will run in one single
586 instance of the newly forked JVM.
587 </p>
588
589 <h4 id="fork">fork</h4>
590
591 <p><em>Since Ant 1.10.6</em></p>
592
593 Tests launched using the <code>junitlauncher</code> task, by default, run in the same JVM that
594 initiates the task. This behaviour can be changed using the <code>fork</code> element.
595 The <code>fork</code> element and its attributes define the characteristics of
596 the new JVM instance that will be created to launch the tests.
597
598 <table class="attr">
599 <tr>
600 <th scope="col">Attribute</th>
601 <th scope="col">Description</th>
602 <th scope="col">Required</th>
603 </tr>
604 <tr>
605 <td>dir</td>
606 <td>The user working directory that will be used for the forked JVM</td>
607 <td>No</td>
608 </tr>
609 <tr>
610 <td>timeout</td>
611 <td>A value in milliseconds, specifying a maximum duration, the test
612 running in this forked JVM is allowed to run. If the test runs longer
613 than this configured value, then the JVM is killed</td>
614 <td>No</td>
615 </tr>
616 <tr>
617 <td>includeJUnitPlatformLibraries</td>
618 <td>If set to <code>true</code>, then the jar files that make up the
619 JUnit platform, will be included in the runtime classpath of the forked
620 JVM. If set to <code>false</code>, then the <a href="#nested-classpath">configured classpath</a>
621 of this task, which will be made available to the runtime classpath of the forked
622 JVM, is expected to contain the JUnit platform library jars</td>
623 <td>No. Value defaults to <code>true</code>.</td>
624 </tr>
625 <tr>
626 <td>includeAntRuntimeLibraries</td>
627 <td>If set to <code>true</code>, then the jar files that make up the
628 Ant runtime, will be included in the runtime classpath of the forked
629 JVM. If set to <code>false</code>, then the <a href="#nested-classpath">configured classpath</a>
630 of this task, which will be made available to the runtime classpath of the forked
631 JVM, is expected to contain the Ant runtime jars</td>
632 <td>No. Value defaults to <code>true</code>.</td>
633 </tr>
634 <tr>
635 <td>java</td>
636 <td>The command used to launch the forked <code>java</code> process. This attribute can be set
637 to point to a different installation of Java than the one that is currently being used to
638 run the Ant build
639 <p><em>Since Ant 1.10.14</em></p>
640 </td>
641 <td>No</td>
642 </tr>
643 <tr>
644 <td>forkMode</td>
645 <td>Controls how many JVMs are launched for the forked tests. Allowed values are:
646 <ul class="inlinelist">
647 <li><code>perTestClass</code> - This mode launches each test class in a
648 separately forked JVM. Each of these JVMs will be forked sequentially
649 one at a time, as and when each test class execution completes.
650 If any <code>timeout</code> value is specified, then that timeout applies to
651 the time that all tests use together, not to an individual test.
652 </li>
653 </ul>
654 <p><em>Since Ant 1.10.14</em></p>
655 </td>
656 <td>No; defaults to launching all test classes in one single forked JVM.</td>
657 </tr>
658 </table>
659
660 The <code>fork</code> element allows the following nested elements:
661
662 <h5>jvmarg</h5>
663 <p>
664 Additional JVM arguments may be passed to the forked JVM via the <code>jvmarg</code> elements.
665 For example:
666 </p>
667 <pre>
668 &lt;fork ...&gt;
669 &lt;jvmarg value="-Dfoo=bar"/&gt;
670 ...
671 &lt;/fork&gt;
672 </pre>
673
674 <p>
675 <code>jvmarg</code> allows all attributes described in <a href="../using.html#arg">Command-line Arguments</a>
676 </p>
677
678 <h5>sysproperty</h5>
679 <p>
680 The <code>sysproperty</code> elements allow passing Java system properties to the forked JVM:
681 </p>
682 <pre>
683 &lt;fork&gt;
684 &lt;sysproperty key="greeting" value="hello world"/&gt;
685 ...
686 &lt;/fork&gt;
687 </pre>
688 <p>
689 The attributes for this element are the same as for <a href="../Tasks/exec.html#env">environment variables</a>
690 </p>
691
692 <h5>syspropertyset</h5>
693
694 <p>
695 You can specify a set of properties to be used as system properties with
696 <a href="../Types/propertyset.html">syspropertyset</a>(s)
697 </p>
698
699
700 <h5>env</h5>
701
702 <p>
703 It is possible to specify environment variables to pass to the forked JVM via
704 nested <code>env</code> elements. For a description of the <code>env</code>
705 element's attributes, see the description in the <a href="../Tasks/exec.html#env">exec</a> task.
706 </p>
707
708 <h5>modulepath</h5>
709
710 <p>
711 The location of Java modules can be specified using the <code>modulepath</code> element,
712 which is a <a href="../using.html#path">path-like structure</a>.
713 </p>
714 For example:
715 <pre>
716 &lt;fork&gt;
717 &lt;modulepath&gt;
718 &lt;pathelement location="lib"/&gt;
719 &lt;pathelement location="dist/test.jar"/&gt;
720 &lt;/modulepath&gt;
721 ...
722 &lt;/fork&gt;
723 </pre>
724
725 <h5>upgrademodulepath</h5>
726
727 <p>
728 The location of Java modules, that replace upgradeable modules in the runtime, can be specified
729 using the <code>upgrademodulepath</code> element, which is a <a href="../using.html#path">path-like
730 structure</a>.
731 </p>
732
733
734 <h3>Examples</h3>
735
736 <p>
737 Launch the JUnit 5 platform to run the <samp>org.myapp.SimpleTest</samp> test
738 </p>
739
740 <pre>
741 &lt;path id="test.classpath"&gt;
742 ...
743 &lt;/path&gt;
744
745 &lt;junitlauncher&gt;
746 &lt;classpath refid="test.classpath"/&gt;
747 &lt;test name="org.myapp.SimpleTest"/&gt;
748 &lt;/junitlauncher&gt;</pre>
749
750 <p>
751 Launch the JUnit 5 platform to run the <samp>org.myapp.SimpleTest</samp> and
752 the <samp>org.myapp.AnotherTest</samp> tests. The build process will be stopped if any test, in
753 the <samp>org.myapp.SimpleTest</samp>, fails.
754 </p>
755
756 <pre>
757 &lt;junitlauncher&gt;
758 &lt;classpath refid="test.classpath"/&gt;
759 &lt;test name="org.myapp.SimpleTest" haltOnFailure="true"/&gt;
760 &lt;test name="org.myapp.AnotherTest"/&gt;
761 &lt;/junitlauncher&gt;
762 </pre>
763
764 <p>
765 Launch the JUnit 5 platform to run only the <samp>testFoo</samp> and <samp>testBar</samp>
766 methods of the <samp>org.myapp.SimpleTest</samp> test class.
767 </p>
768
769 <pre>
770 &lt;junitlauncher&gt;
771 &lt;classpath refid="test.classpath"/&gt;
772 &lt;test name="org.myapp.SimpleTest" methods="testFoo, testBar"/&gt;
773 &lt;/junitlauncher&gt;</pre>
774
775 <p>
776 Select any <samp>.class</samp> files that match
777 the <samp>org/example/**/tests/**/</samp> <code>fileset</code> filter, under
778 the <samp>${build.classes.dir}</samp> and passes those classes to the JUnit 5 platform for
779 execution as tests.
780 </p>
781
782 <pre>
783 &lt;junitlauncher&gt;
784 &lt;classpath refid="test.classpath"/&gt;
785
786 &lt;testclasses outputdir="${output.dir}"&gt;
787 &lt;fileset dir="${build.classes.dir}"&gt;
788 &lt;include name="org/example/**/tests/**/"/&gt;
789 &lt;/fileset&gt;
790 &lt;/testclasses&gt;
791 &lt;/junitlauncher&gt;</pre>
792
793 <p>
794 Select any <samp>.class</samp> files that match
795 the <samp>org/example/**/tests/**/</samp> <code>fileset</code> filter, under
796 the <samp>${build.classes.dir}</samp> and pass those classes to the JUnit 5 platform for
797 execution as tests. Test results will be written out to the <samp>${output.dir}</samp> by
798 the <q>legacy-xml</q> and <q>legacy-plain</q> formatters, in separate files. Furthermore, both
799 the <q>legacy-xml</q> and the <q>legacy-plain</q> listeners, above, are configured to receive
800 the standard output content generated by the tests. The <q>legacy-xml</q> listener is configured
801 to receive standard error content as well.
802 </p>
803
804 <pre>
805 &lt;junitlauncher&gt;
806 &lt;classpath refid="test.classpath"/&gt;
807
808 &lt;testclasses outputdir="${output.dir}"&gt;
809 &lt;fileset dir="${build.classes.dir}"&gt;
810 &lt;include name="org/example/**/tests/**/"/&gt;
811 &lt;/fileset&gt;
812 &lt;listener type="legacy-xml" sendSysOut="true" sendSysErr="true"/&gt;
813 &lt;listener type="legacy-plain" sendSysOut="true" /&gt;
814 &lt;/testclasses&gt;
815 &lt;/junitlauncher&gt;</pre>
816
817 </body>
818 </html>