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 kB

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