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