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 26 KiB

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