You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

junitlauncher.html 28 KiB

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