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.

junit.html 22 KiB

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