2000-08-09 13:12:13 +00:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<h2><a name="junit">JUnit</a></h2>
|
|
|
|
<h3>Description</h3>
|
|
|
|
|
|
|
|
<p>This task runs tests from the JUnit testing framework. The latest
|
2000-09-20 15:22:00 +00:00
|
|
|
version of the framework can be found at
|
|
|
|
<a href="http://www.junit.org">http://www.junit.org</a>.
|
2001-05-22 09:20:17 +00:00
|
|
|
This task has been tested with JUnit 3.0 up to JUnit 3.7, it won't
|
|
|
|
work with versions prior to JUnit 3.0.</p>
|
2000-08-09 13:12:13 +00:00
|
|
|
|
|
|
|
<p>Tests are defined by nested <code>test</code> or
|
|
|
|
<code>batchtest</code> tags, see <a href="#nested">nested
|
|
|
|
elements</a>.</p>
|
|
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td width="12%" valign="top"><b>Attribute</b></td>
|
|
|
|
<td width="78%" valign="top"><b>Description</b></td>
|
|
|
|
<td width="10%" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">printsummary</td>
|
2001-05-04 08:03:53 +00:00
|
|
|
<td valign="top">Print one line statistics for each testcase. Can
|
|
|
|
take the values "on", "off" and
|
|
|
|
"withOutAndErr" - "withOutAndErr" is the same
|
2001-10-14 03:49:07 +00:00
|
|
|
as "on" but also includes the output of the test
|
|
|
|
as written to System.out and System.err.</td>
|
2000-08-09 13:12:13 +00:00
|
|
|
<td align="center" valign="top">No, default is "off"</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">fork</td>
|
|
|
|
<td valign="top">Run the tests in a separate VM.</td>
|
|
|
|
<td align="center" valign="top">No, default is "off"</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">haltonerror</td>
|
2000-08-09 15:50:23 +00:00
|
|
|
<td valign="top">Stop the build process if an error occurs during the test
|
2000-08-09 13:12:13 +00:00
|
|
|
run.</td>
|
|
|
|
<td align="center" valign="top">No, default is "off"</td>
|
|
|
|
</tr>
|
2001-07-17 13:09:48 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">errorProperty</td>
|
|
|
|
<td valign="top">The name of a property to set in the event of an error.</td>
|
|
|
|
<td align="center" valign="top">No.</td>
|
|
|
|
</tr>
|
2000-08-09 13:12:13 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">haltonfailure</td>
|
|
|
|
<td valign="top">Stop the build process if a test fails (errors are
|
|
|
|
considered failures as well).</td>
|
|
|
|
<td align="center" valign="top">No, default is "off"</td>
|
|
|
|
</tr>
|
2001-07-17 13:09:48 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">failureProperty</td>
|
|
|
|
<td valign="top">The name of a property to set in the event of a failure
|
|
|
|
(errors are considered failures as well).</td>
|
|
|
|
<td align="center" valign="top">No.</td>
|
|
|
|
</tr>
|
2000-08-09 13:12:13 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">timeout</td>
|
|
|
|
<td valign="top">Cancel the individual tests if the don't finish
|
|
|
|
in the given time (measured in milliseconds). Ignored if fork is
|
|
|
|
disabled.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">maxmemory</td>
|
|
|
|
<td valign="top">Max amount of memory to allocate to the forked VM
|
|
|
|
(ignored if fork is disabled)</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">jvm</td>
|
|
|
|
<td valign="top">the command used to invoke the Java Virtual Machine,
|
|
|
|
default is 'java'. The command is resolved by java.lang.Runtime.exec().
|
|
|
|
Ignored if fork is disabled.</td>
|
|
|
|
<td align="center" valign="top">No, default "java"</td>
|
|
|
|
</tr>
|
2000-09-19 16:25:40 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">dir</td>
|
|
|
|
<td valign="top">The directory to invoke the VM in. (ignored if
|
|
|
|
fork is disabled)</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
2000-08-09 13:12:13 +00:00
|
|
|
</table>
|
|
|
|
|
|
|
|
<h3><a name="nested">Nested Elements</a></h3>
|
|
|
|
|
|
|
|
<p><code>junit</code> supports a nested <code><classpath></code>
|
2001-02-13 12:32:01 +00:00
|
|
|
element, that represents a <a href="../using.html#path">PATH like
|
2000-10-05 09:12:07 +00:00
|
|
|
structure</a>.</p>
|
2000-08-09 13:12:13 +00:00
|
|
|
|
|
|
|
<h4>jvmarg</h4>
|
|
|
|
|
|
|
|
<p>If fork is enabled, additional parameters may be passed to the new
|
2001-09-08 01:05:18 +00:00
|
|
|
VM via nested <code><jvmarg></code> attributes, for example:</p>
|
2000-08-09 13:12:13 +00:00
|
|
|
|
2001-02-13 12:32:01 +00:00
|
|
|
<pre>
|
2000-08-09 13:12:13 +00:00
|
|
|
<junit fork="yes">
|
|
|
|
<jvmarg value="-Djava.compiler=NONE"/>
|
2001-01-30 17:01:39 +00:00
|
|
|
...
|
2000-08-09 13:12:13 +00:00
|
|
|
</junit>
|
2001-02-13 12:32:01 +00:00
|
|
|
</pre>
|
|
|
|
|
2001-09-08 01:05:18 +00:00
|
|
|
<p>would run the test in a VM without JIT.</p>
|
2000-08-09 13:12:13 +00:00
|
|
|
|
2000-08-09 15:50:23 +00:00
|
|
|
<p><code><jvmarg></code> allows all attributes described in <a
|
2001-02-13 12:32:01 +00:00
|
|
|
href="../using.html#arg">Command line arguments</a>.</p>
|
2000-08-09 13:12:13 +00:00
|
|
|
|
2001-01-30 17:01:39 +00:00
|
|
|
<h4>sysproperty</h4>
|
|
|
|
|
|
|
|
<p>Use nested <code><sysproperty></code> elements to specify system
|
|
|
|
properties required by the class. These properties will be made available
|
|
|
|
to the VM during the execution of the test (either ANT's VM or the forked VM).
|
2001-09-08 01:05:18 +00:00
|
|
|
The attributes for this element are the same as for <a href="../CoreTasks/exec.html#env">environment variables</a>.</p>
|
2001-01-30 17:01:39 +00:00
|
|
|
|
2001-02-13 12:32:01 +00:00
|
|
|
<pre>
|
2001-01-30 17:01:39 +00:00
|
|
|
<junit fork="no">
|
|
|
|
<sysproperty key="basedir" value="${basedir}"/>
|
|
|
|
...
|
|
|
|
</junit>
|
2001-02-13 12:32:01 +00:00
|
|
|
</pre>
|
|
|
|
|
2001-09-08 01:05:18 +00:00
|
|
|
<p>would run the test in ANT's VM and make the <code>basedir</code> property
|
2001-01-30 17:01:39 +00:00
|
|
|
available to the test.</p>
|
|
|
|
|
|
|
|
|
2000-08-09 13:12:13 +00:00
|
|
|
<h4>formatter</h4>
|
|
|
|
|
|
|
|
<p>The results of the tests can be printed in different
|
2000-09-14 08:13:06 +00:00
|
|
|
formats. Output will always be sent to a file unless you set the
|
|
|
|
usefile attribute to false, the name of the file is determined by the
|
|
|
|
name of the test and can be set by the <code>outfile</code> attribute
|
2001-09-08 01:05:18 +00:00
|
|
|
of <code><test></code>.</p>
|
2000-08-09 13:12:13 +00:00
|
|
|
|
2001-05-04 08:03:53 +00:00
|
|
|
<p>There are three predefined formatters, one prints the test results
|
|
|
|
in XML format, the other emit plain text. The formatter named
|
|
|
|
"brief" will only print detailed information for testcases
|
|
|
|
that failed, while "plain" gives a little statistics line
|
|
|
|
for all test cases. Custom formatters that need to implement
|
2000-08-09 13:12:13 +00:00
|
|
|
<code>org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter</code>
|
|
|
|
can be specified.</p>
|
|
|
|
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td width="12%" valign="top"><b>Attribute</b></td>
|
|
|
|
<td width="78%" valign="top"><b>Description</b></td>
|
|
|
|
<td width="10%" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">type</td>
|
2001-05-04 08:03:53 +00:00
|
|
|
<td valign="top">Use a predefined formatter (either
|
|
|
|
"xml", "plain" or "brief").</td>
|
2000-08-09 13:12:13 +00:00
|
|
|
<td align="center" rowspan="2">Exactly one of these.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">classname</td>
|
2000-08-09 15:50:23 +00:00
|
|
|
<td valign="top">Name of a custom formatter class.</td>
|
2000-08-09 13:12:13 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">extension</td>
|
|
|
|
<td valign="top">Extension to append to the output filename.</td>
|
|
|
|
<td align="center">Yes, if classname has been used.</td>
|
|
|
|
</tr>
|
2000-09-14 08:13:06 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">usefile</td>
|
|
|
|
<td valign="top">Boolean that determines whether output should be
|
|
|
|
sent to a file.</td>
|
|
|
|
<td align="center">No, default true.</td>
|
|
|
|
</tr>
|
2000-08-09 13:12:13 +00:00
|
|
|
</table>
|
|
|
|
|
|
|
|
<h4>test</h4>
|
|
|
|
|
|
|
|
<p>Defines a single test class.</p>
|
|
|
|
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td width="12%" valign="top"><b>Attribute</b></td>
|
|
|
|
<td width="78%" valign="top"><b>Description</b></td>
|
|
|
|
<td width="10%" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">name</td>
|
|
|
|
<td valign="top">Name of the test class</td>
|
|
|
|
<td align="center">Yes</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">fork</td>
|
|
|
|
<td valign="top">Run the tests in a separate VM.
|
|
|
|
Overrides value set in <code><junit></code>.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">haltonerror</td>
|
2000-08-09 15:50:23 +00:00
|
|
|
<td valign="top">Stop the build process if an error occurs during the test
|
2000-08-09 13:12:13 +00:00
|
|
|
run. Overrides value set in <code><junit></code>.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
2001-07-17 13:09:48 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">errorProperty</td>
|
|
|
|
<td valign="top">The name of a property to set in the event of an error.
|
|
|
|
Overrides value set in <junit>.</td>
|
|
|
|
<td align="center" valign="top">No.</td>
|
|
|
|
</tr>
|
2000-08-09 13:12:13 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">haltonfailure</td>
|
|
|
|
<td valign="top">Stop the build process if a test fails (errors are
|
|
|
|
considered failures as well). Overrides value set in
|
|
|
|
<code><junit></code>.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
2001-07-17 13:09:48 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">failureProperty</td>
|
|
|
|
<td valign="top">The name of a property to set in the event of a failure
|
|
|
|
(errors are considered failures as well). Overrides value set in <junit>.</td>
|
|
|
|
<td align="center" valign="top">No.</td>
|
|
|
|
</tr>
|
2000-12-19 12:07:58 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">todir</td>
|
|
|
|
<td valign="top">Directory to write the reports to.</td>
|
|
|
|
<td align="center" valign="top">No, default is current directory.</td>
|
|
|
|
</tr>
|
2000-08-09 13:12:13 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">outfile</td>
|
2000-08-09 15:50:23 +00:00
|
|
|
<td valign="top">Base name of the test result. The full filename is
|
2000-08-09 13:12:13 +00:00
|
|
|
determined by this attribute and the extension of
|
|
|
|
<code>formatter</code>.</td>
|
|
|
|
<td align="center" valign="top">No, default is
|
|
|
|
<code>TEST-name</code> using the <code>name</code> attribute.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">if</td>
|
|
|
|
<td valign="top">Only run test if the named property is set.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">unless</td>
|
|
|
|
<td valign="top">Only run test if the named property is <b>not</b> set.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<p>Tests can define their own formatters via nested
|
|
|
|
<code><formatter></code> elements.</p>
|
|
|
|
|
|
|
|
<h4>batchtest</h4>
|
|
|
|
|
|
|
|
<p>Define a number of tests based on pattern matching.</p>
|
|
|
|
|
|
|
|
<p><code>batchtest</code> collects the included files from any number
|
2000-08-10 11:23:02 +00:00
|
|
|
of nested <a
|
2001-02-13 12:32:01 +00:00
|
|
|
href="../CoreTypes/fileset.html"><code><fileset></code></a>s. It then
|
2000-09-07 09:51:02 +00:00
|
|
|
generates a test class name for each file that ends in
|
|
|
|
<code>.java</code> or <code>.class</code>.</p>
|
2000-08-09 13:12:13 +00:00
|
|
|
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td width="12%" valign="top"><b>Attribute</b></td>
|
|
|
|
<td width="78%" valign="top"><b>Description</b></td>
|
|
|
|
<td width="10%" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">fork</td>
|
|
|
|
<td valign="top">Run the tests in a separate VM.
|
|
|
|
Overrides value set in <code><junit></code>.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">haltonerror</td>
|
2000-08-09 15:50:23 +00:00
|
|
|
<td valign="top">Stop the build process if an error occurs during the test
|
2000-08-09 13:12:13 +00:00
|
|
|
run. Overrides value set in <code><junit></code>.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
2001-07-17 13:09:48 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">errorProperty</td>
|
|
|
|
<td valign="top">The name of a property to set in the event of an error.
|
|
|
|
Overrides value set in <junit>.</td>
|
|
|
|
<td align="center" valign="top">No.</td>
|
|
|
|
</tr>
|
2000-08-09 13:12:13 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">haltonfailure</td>
|
|
|
|
<td valign="top">Stop the build process if a test fails (errors are
|
|
|
|
considered failures as well). Overrides value set in
|
|
|
|
<code><junit></code>.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
2001-07-17 13:09:48 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">failureProperty</td>
|
|
|
|
<td valign="top">The name of a property to set in the event of a failure
|
|
|
|
(errors are considered failures as well). Overrides value set in <junit></td>
|
|
|
|
<td align="center" valign="top">No.</td>
|
|
|
|
</tr>
|
2000-12-19 12:07:58 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">todir</td>
|
|
|
|
<td valign="top">Directory to write the reports to.</td>
|
|
|
|
<td align="center" valign="top">No, default is current directory.</td>
|
|
|
|
</tr>
|
2000-08-09 13:12:13 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">if</td>
|
|
|
|
<td valign="top">Only run tests if the named property is set.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">unless</td>
|
|
|
|
<td valign="top">Only run tests if the named property is <b>not</b> set.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<p>Batchtests can define their own formatters via nested
|
|
|
|
<code><formatter></code> elements.</p>
|
|
|
|
|
|
|
|
<h3>Examples</h3>
|
2001-02-13 12:32:01 +00:00
|
|
|
|
2001-09-08 01:05:18 +00:00
|
|
|
<pre>
|
2000-08-09 13:12:13 +00:00
|
|
|
<junit>
|
|
|
|
<test name="my.test.TestCase" />
|
|
|
|
</junit>
|
2001-02-13 12:32:01 +00:00
|
|
|
</pre>
|
2000-08-09 13:12:13 +00:00
|
|
|
|
2001-09-08 01:05:18 +00:00
|
|
|
<p>Runs the test defined in <code>my.test.TestCase</code> in the same
|
2000-08-09 13:12:13 +00:00
|
|
|
VM. No output will be generated unless the test fails.</p>
|
|
|
|
|
2001-09-08 01:05:18 +00:00
|
|
|
<pre>
|
2000-08-09 13:12:13 +00:00
|
|
|
<junit printsummary="yes" fork="yes" haltonfailure="yes">
|
|
|
|
<formatter type="plain" />
|
|
|
|
<test name="my.test.TestCase" />
|
|
|
|
</junit>
|
2001-02-13 12:32:01 +00:00
|
|
|
</pre>
|
2000-08-09 13:12:13 +00:00
|
|
|
|
2001-09-08 01:05:18 +00:00
|
|
|
<p>Runs the test defined in <code>my.test.TestCase</code> in a
|
2000-08-09 13:12:13 +00:00
|
|
|
separate VM. At the end of the test a single line summary will be
|
|
|
|
printed. A detailed report of the test can be found in
|
|
|
|
<code>TEST-my.test.TestCase.txt</code>. The build process will be
|
|
|
|
stopped if the test fails.</p>
|
|
|
|
|
2001-09-08 01:05:18 +00:00
|
|
|
<pre>
|
2000-08-09 13:12:13 +00:00
|
|
|
<junit printsummary="yes" haltonfailure="yes">
|
|
|
|
<classpath>
|
|
|
|
<pathelement location="${build.tests}" />
|
|
|
|
<pathelement path="${java.class.path}" />
|
|
|
|
</classpath>
|
|
|
|
|
|
|
|
<formatter type="plain" />
|
|
|
|
|
|
|
|
<test name="my.test.TestCase" haltonfailure="no" outfile="result" >
|
|
|
|
<formatter type="xml" />
|
|
|
|
</test>
|
|
|
|
|
2000-12-19 12:07:58 +00:00
|
|
|
<batchtest fork="yes" todir="${reports.tests}">
|
2000-08-09 13:12:13 +00:00
|
|
|
<fileset dir="${src.tests}">
|
|
|
|
<include name="**/*Test*.java" />
|
2001-02-13 12:32:01 +00:00
|
|
|
<exclude name="**/AllTests.java" />
|
2000-08-09 13:12:13 +00:00
|
|
|
</fileset>
|
|
|
|
</batchtest>
|
|
|
|
</junit>
|
2001-02-13 12:32:01 +00:00
|
|
|
</pre>
|
2000-08-09 13:12:13 +00:00
|
|
|
|
2001-09-08 01:05:18 +00:00
|
|
|
<p>Runs <code>my.test.TestCase</code> in the same VM (ignoring the
|
2000-08-09 13:12:13 +00:00
|
|
|
given CLASSPATH), only a warning is printed if this test fails. In
|
2000-08-09 15:50:23 +00:00
|
|
|
addition to the plain text test results, for this test a XML result
|
2000-08-09 13:12:13 +00:00
|
|
|
will be output to <code>result.xml</code>.</p>
|
|
|
|
|
|
|
|
<p>For each matching file in the directory <code>${src.tests}</code> a
|
|
|
|
test is run in a separate VM. If a test fails, the build process is
|
|
|
|
aborted. Results are collected in files named
|
2000-12-19 12:07:58 +00:00
|
|
|
<code>TEST-<em>name</em>.txt</code> and written to <code>${reports.tests}</code>.</p>
|
2000-08-09 13:12:13 +00:00
|
|
|
|
2001-07-17 13:09:48 +00:00
|
|
|
<p>By using the errorProperty and failureProperty tags, it is possible to
|
|
|
|
perform setup work (such as starting an external server), execute the test,
|
|
|
|
clean up, and still fail the build in the event of a failure.</p>
|
|
|
|
|
2000-08-09 13:12:13 +00:00
|
|
|
</body>
|
|
|
|
</html>
|