source: release-kits/lirk3/ant-scripts/tasks/antelope/docs/manual/bk03ch26.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 6.3 KB
Line 
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 26. TestCase Task</title><meta name="generator" content="DocBook XSL Stylesheets V1.68.1"><link rel="start" href="index.html" title="Antelope Users Guide"><link rel="up" href="bk03.html" title="Additional Ant Tasks"><link rel="prev" href="bk03ch25.html" title="Chapter 25. Suite Task"><link rel="next" href="bk03ch27.html" title="Chapter 27. Performance Monitoring"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 26. TestCase Task</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk03ch25.html">Prev</a> </td><th width="60%" align="center">Additional Ant Tasks</th><td width="20%" align="right"> <a accesskey="n" href="bk03ch27.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="testcasetask"></a>Chapter 26. TestCase Task</h2></div></div></div>
2<STYLE TYPE="text/css"> <!-- @import url(./style.css); --> </STYLE>
3 <p>
4 Modeled after the TestCase provided by jUnit, this class is an Ant task that
5 looks through the build file that contains this task, calls a 'setUp' target
6 (if it exists), then all targets whose names start with 'test', and last calls
7 a target named 'tearDown' (if it exists). Both 'setUp' and 'tearDown' are
8 optional targets in the build file.
9</p><p>
10 Ant stores targets in a hashtable, so there is no guaranteed order in which
11 the 'test*' targets will be called. If order is important, use the 'depends'
12 attribue of a target to enforce order, and do not name dependent targets with
13 a name starting with 'test'.
14</p><p>
15 Most unit tests will make use of Assert. As the Assert task requires that the property "ant.enable.asserts" be set to true before it will do anything, this task automatically sets this property to true. The Assert task has a "level" attribute. By default, the level is set to "error", so if the Assert fails, the TestCase fails. If the level is set to "warning", the test case will be marked as a warning rather than a failure. If the level is set to "info" or "debug" and the Assert fails, any message associated with the Assert will be written out, but otherwise will be ignored by TestCase.
16</p><p>
17To use this task in your build files, include a task definition like this:
18</p><pre class="programlisting">
19
20 &lt;taskdef name="testcase" classname="ise.antelope.tasks.TestCase"/&gt;
21
22</pre><p>
23</p><p>
24</p><div class="table"><a name="id2526309"></a><p class="title"><b>Table 26.1. TestCase Attributes</b></p><table summary="TestCase Attributes" border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>file</td><td>The file containing tests.</td><td>None</td><td>Yes</td></tr><tr><td>enabled</td><td>Determines if this test should be ran. By using a property for this attribute, it is easy to turn off/on multiple tests.</td><td>On</td><td>No</td></tr><tr><td>assertenabled</td><td>Generally tests will use the Assert task. This attribute sets whether asserts should be enabled.</td><td>Yes</td><td>No</td></tr><tr><td>failonerror</td><td>If true, cause the build to fail. By default, a failed test does not cause the build to fail, so all tests may have the opportunity to run.</td><td>No</td><td>No</td></tr><tr><td>showoutput</td><td>If true, show intermediate test results</td><td>Yes</td><td>No</td></tr><tr><td>showsummary</td><td>If true, show a summary of test results at the end of the test run.</td><td>Yes</td><td>Yes</td></tr></tbody></table></div><p>
25</p><p>
26TestCase is most often used in conjunction with the Suite task.
27</p><p>
28</p><pre class="programlisting">
29
30&lt;project name="mathtest" basedir="." default="suite"
31 xmlns:a="antlib:ise.antelope.tasks"&gt;
32
33 &lt;description&gt;
34 Build file to run unit tests for the Math task
35 &lt;/description&gt;
36
37 &lt;a:suite&gt;
38 &lt;a:testcase file="math_basic_tests.xml"/&gt;
39 &lt;a:testcase file="math_rules_tests.xml"/&gt;
40 &lt;a:testcase file="math_precision_tests.xml"/&gt;
41 &lt;/a:suite&gt;
42
43&lt;/project&gt;
44
45</pre><p>
46</p><p>
47Here is an example build file containing actual tests. The 'setUp' target will execute first, then the two test targets.
48</p><p>
49</p><pre class="programlisting">
50
51&lt;project name="math_precision_tests" basedir="." default="suite"
52 xmlns:a="antlib:ise.antelope.tasks"&gt;
53
54 &lt;target name="setUp"&gt;
55 &lt;echo&gt;Running math precision tests.&lt;/echo&gt;
56 &lt;/target&gt;
57
58 &lt;target name="test10"&gt;
59 &lt;echo&gt;Circle area test&lt;/echo&gt;
60 &lt;a:math result="pi"&gt;
61 &lt;a:op op="*"&gt;
62 &lt;a:num value="PI"/&gt;
63 &lt;a:op op="pow"&gt;
64 &lt;a:num value="1"/&gt;
65 &lt;a:num value="2"/&gt;
66 &lt;/a:op&gt;
67 &lt;/a:op&gt;
68 &lt;/a:math&gt;
69 &lt;a:assert message="failed circle area test"&gt;
70 &lt;a:bool&gt;
71 &lt;a:startswith string="${pi}" with="3.141592653589793"/&gt;
72 &lt;/a:bool&gt;
73 &lt;/a:assert&gt;
74 &lt;/target&gt;
75
76 &lt;target name="test11"&gt;
77 &lt;echo&gt;Division by zero test&lt;/echo&gt;
78 &lt;!-- division by zero --&gt;
79 &lt;a:try&gt;
80 &lt;a:math result="x"&gt;
81 &lt;a:op op="/"&gt;
82 &lt;a:num value="PI"/&gt;
83 &lt;a:num value="0"/&gt;
84 &lt;/a:op&gt;
85 &lt;/a:math&gt;
86 &lt;fail&gt;Division by 0 succeeded: ${x}&lt;/fail&gt;
87 &lt;catch&gt;
88 &lt;assert/&gt;
89 &lt;/catch&gt;
90 &lt;/a:try&gt;
91 &lt;/target&gt;
92
93&lt;/project&gt;
94
95</pre><p>
96</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk03ch25.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="bk03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk03ch27.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 25. Suite Task </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 27. Performance Monitoring</td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.