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

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