/[eiffelstudio]/vendor/gobosoft.com/gobo/current/doc/getest/assertions.html
ViewVC logotype

Contents of /vendor/gobosoft.com/gobo/current/doc/getest/assertions.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 90767 - (show annotations)
Tue Jan 22 00:56:30 2013 UTC (6 years, 8 months ago) by manus
File MIME type: text/xml
File size: 10776 byte(s)
Updated svn:eol-style to be native and svn:mime-style to be text/xml

1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3
4 <head>
5 <meta http-equiv="Content-Type"
6 content="text/html; charset=iso-8859-1">
7 <meta name="GENERATOR" content="Microsoft FrontPage 2.0">
8 <title>Getest: Assertions</title>
9 </head>
10
11 <body bgcolor="#FFFFFF">
12
13 <table border="0" width="100%">
14 <tr>
15 <td><font size="6"><strong>Assertions</strong></font></td>
16 <td align="right"><a href="examples.html"><img
17 src="../image/previous.gif" alt="Previous" border="0"
18 width="40" height="40"></a><a href="configuration.html"><img
19 src="../image/next.gif" alt="Next" border="0" width="40"
20 height="40"></a></td>
21 </tr>
22 </table>
23
24 <hr size="1">
25
26 <p>The test routines in the test case classes can use assertion
27 features defined in class <font color="#008080"><em><tt>TS_ASSERTION_ROUTINES</tt></em></font>.
28 Assertions routines have the prefix <font color="#008080"><em><tt>assert</tt></em></font>
29 and when they are not true an error is reported to the test suite
30 with the name of the test (i.e. feature name of the test routine)
31 and the assertion tag. Assertion routines are inherited from
32 class <font color="#008080"><em><tt>TS_TEST_CASE</tt></em></font>
33 from the test harness cluster of the <em>Gobo Eiffel Test Library</em>.
34 Following are the predefined assertion routines available so far:</p>
35
36 <blockquote>
37 <pre><em>assert </em>(<em>a_tag</em>:<em> STRING</em>;<em> a_condition</em>:<em> BOOLEAN</em>)<em>
38 </em><font color="#008000"> -- Assert </font><em>a_condition</em><font
39 color="#008000">.</font><em>
40 </em><font color="#000080"><em><strong>require</strong></em></font><em>
41 a_tag_not_void</em>:<em> a_tag </em>/=<em> </em><font
42 color="#008080"><em>Void</em></font></pre>
43 <pre><em>assert_equal </em>(<em>a_tag</em>:<em> STRING</em>;<em> expected</em>,<em> actual</em>:<em> ANY</em>)<em>
44 </em><font color="#008000"> -- Assert that </font><em>equal</em><font
45 color="#008000"> (</font><em>expected</em><font color="#008000">, </font><em>actual</em><font
46 color="#008000">).</font><em>
47 </em><font color="#000080"><em><strong>require</strong></em></font><em>
48 a_tag_not_void</em>:<em> a_tag </em>/=<em> </em><font
49 color="#008080"><em>Void</em></font></pre>
50 <pre><em>assert_not_equal </em>(<em>a_tag</em>:<em> STRING</em>;<em> expected</em>,<em> actual</em>:<em> ANY</em>)<em>
51 </em><font color="#008000"> -- Assert that </font><font
52 color="#000080"><em><strong>not</strong></em></font><em> equal</em><font
53 color="#008000"> (</font><em>expected</em><font color="#008000">, </font><em>actual</em><font
54 color="#008000">).</font><em>
55 </em><font color="#000080"><em><strong>require</strong></em></font><em>
56 a_tag_not_void</em>:<em> a_tag </em>/=<em> </em><font
57 color="#008080"><em>Void</em></font></pre>
58 <pre><em>assert_same </em>(<em>a_tag</em>:<em> STRING</em>;<em> expected</em>,<em> actual</em>:<em> ANY</em>)<em>
59 </em><font color="#008000"> -- Assert that </font><em>expected</em><font
60 color="#008000"> = </font><em>actual</em><font color="#008000">.</font><em>
61 </em><font color="#000080"><em><strong>require</strong></em></font><em>
62 a_tag_not_void</em>:<em> a_tag </em>/=<em> </em><font
63 color="#008080"><em>Void</em></font></pre>
64 <pre><em>assert_arrays_same </em>(<em>a_tag</em>:<em> STRING</em>;<em> expected</em>,<em> actual</em>:<em> ARRAY </em>[<em>ANY</em>])<em>
65 </em><font color="#008000"> -- Assert that </font><em>expected</em><font
66 color="#008000"> and </font><em>actual</em><font color="#008000"> have the same items
67 -- in the same order (use '=' for item comparison).</font><em>
68 </em><font color="#000080"><em><strong>require</strong></em></font><em>
69 a_tag_not_void</em>:<em> a_tag </em>/=<em> </em><font
70 color="#008080"><em>Void</em></font><em>
71 expected_not_void</em>:<em> expected </em>/=<em> </em><font
72 color="#008080"><em>Void</em></font><em>
73 actual_not_void</em>:<em> actual </em>/=<em> </em><font
74 color="#008080"><em>Void</em></font></pre>
75 <pre><em>assert_arrays_equal </em>(<em>a_tag</em>:<em> STRING</em>;<em> expected</em>,<em> actual</em>:<em> ARRAY </em>[<em>ANY</em>])<em>
76 </em><font color="#008000"> -- Assert that </font><em>expected</em><font
77 color="#008000"> and </font><em>actual</em><font color="#008000"> have the same items
78 -- in the same order (use </font><em>equal</em><font
79 color="#008000"> for item comparison).</font><em>
80 </em><font color="#000080"><em><strong>require</strong></em></font><em>
81 a_tag_not_void</em>:<em> a_tag </em>/=<em> </em><font
82 color="#008080"><em>Void</em></font><em>
83 expected_not_void</em>:<em> expected </em>/=<em> </em><font
84 color="#008080"><em>Void</em></font><em>
85 actual_not_void</em>:<em> actual </em>/=<em> </em><font
86 color="#008080"><em>Void</em></font></pre>
87 <pre><em>assert_iarrays_same </em>(<em>a_tag</em>:<em> STRING</em>;<em> expected</em>,<em> actual</em>:<em> ARRAY </em>[<em>INTEGER</em>])<em>
88 </em><font color="#008000"> -- Assert that </font><em>expected</em><font
89 color="#008000"> and </font><em>actual</em><font color="#008000"> have the same items
90 -- in the same order (use '=' for item comparison).</font><em>
91 </em><font color="#000080"><em><strong>require</strong></em></font><em>
92 a_tag_not_void</em>:<em> a_tag </em>/=<em> </em><font
93 color="#008080"><em>Void</em></font><em>
94 expected_not_void</em>:<em> expected </em>/=<em> </em><font
95 color="#008080"><em>Void</em></font><em>
96 actual_not_void</em>:<em> actual </em>/=<em> </em><font
97 color="#008080"><em>Void</em></font></pre>
98 </blockquote>
99
100 <p>Test cases that require a common setup or tear down can
101 redefine the features <font color="#008080"><em><tt>set_up</tt></em></font>
102 and <font color="#008080"><em><tt>tear_down</tt></em></font> from
103 <font color="#008080"><em><tt>TS_TEST_CASE </tt></em></font>to
104 achieve that effect.</p>
105
106 <blockquote>
107 <pre><em>set_up
108 </em><font color="#008000"> -- Setup for a test.
109 -- (Can be redefined in descendant classes.)</font></pre>
110 <pre><em>tear_down
111 </em><font color="#008000"> -- Tear down after a test.
112 -- (Can be redefined in descendant classes.)</font></pre>
113 </blockquote>
114
115 <p>Here is a simple example which tests a database class:</p>
116
117 <blockquote>
118 <pre><font color="#000080"><em><strong>class</strong></em></font><em> TEST_DATABASE
119
120 </em><font color="#000080"><em><strong>inherit</strong></em></font><em>
121
122 TS_TEST_CASE
123 </em><font color="#000080"><em><strong>redefine</strong></em></font><em>
124 set_up</em>,<em> tear_down
125 </em><font color="#000080"><em><strong> end
126
127 create</strong></em></font><em>
128
129 make_default
130 </em><font color="#000080"><em><strong>
131 feature</strong></em></font><em> </em><font color="#008000">-- Access
132 </font><em>
133 db: DATABASE
134 </em><font color="#008000"> -- Database to be tested</font><em>
135
136 </em><font color="#000080"><em><strong>feature</strong></em></font><em> </em><font
137 color="#008000">-- Setting</font><em>
138
139 set_up
140 </em><font color="#008000"> -- Connect to the database.</font><em>
141 </em><font color="#000080"><em><strong>do</strong></em></font><em>
142 </em><font color="#000080"><em><strong>create</strong></em></font><em> db</em>.<em>make
143 db</em>.<em>connect
144 </em><font color="#000080"><em><strong>end</strong></em></font><em>
145
146 tear_down
147 </em><font color="#008000"> -- Disconnect from the database.</font><em>
148 </em><font color="#000080"><em><strong>do</strong></em></font><em>
149 db</em>.<em>disconnect
150 db </em>:=<em> </em><font color="#008080"><em>Void</em></font><em>
151 </em><font color="#000080"><em><strong>end</strong></em></font><em>
152
153 </em><font color="#000080"><em><strong>feature</strong></em></font><em> </em><font
154 color="#008000">-- Test</font><em>
155
156 test_connection
157 </em><font color="#008000"> -- Test database connection.</font><em>
158 </em><font color="#000080"><em><strong>do</strong></em></font><em>
159 assert </em>(<font color="#800000"><em>&quot;db_not_void&quot;</em></font>,<em> db </em>/=<em> </em><font
160 color="#008080"><em>Void</em></font>)<em>
161 assert </em>(<font color="#800000"><em>&quot;db_connected&quot;</em></font>,<em> db</em>.<em>is_connected</em>)<em>
162 </em><font color="#000080"><em><strong>end</strong></em></font><em>
163
164 test_insertion
165 </em><font color="#008000"> -- Test insertion in database.</font><em>
166 </em><font color="#000080"><em><strong>do</strong></em></font><em>
167 db.put </em>(<font color="#800000"><em>&quot;gobo&quot;</em></font>,<em> </em><font
168 color="#800000"><em>&quot;name&quot;</em></font>)<em>
169 assert </em>(<font color="#800000"><em>&quot;db_has_name&quot;</em></font>,<em> db.has </em>(<font
170 color="#800000"><em>&quot;name&quot;</em></font>))<em>
171 assert_equal (</em><font color="#800000"><em>&quot;inserted&quot;</em></font><em>, </em><font
172 color="#800000"><em>&quot;gobo&quot;</em></font><em>, db</em>.<em>item </em>(<font
173 color="#800000"><em>&quot;name&quot;</em></font>))<em>
174 </em><font color="#000080"><em><strong>end</strong></em></font><em>
175
176 </em><font color="#000080"><em><strong>end</strong></em></font><em> </em></pre>
177 </blockquote>
178
179 <hr size="1">
180
181 <table border="0" width="100%">
182 <tr>
183 <td><address>
184 <font size="2"><b>Copyright 2001-2008</b></font><font
185 size="1"><b>, </b></font><font size="2"><strong>Eric
186 Bezault</strong></font><strong> </strong><font
187 size="2"><br>
188 <strong>mailto:</strong></font><a
189 href="mailto:ericb@gobosoft.com"><font size="2">ericb@gobosoft.com</font></a><font
190 size="2"><br>
191 <strong>http:</strong></font><a
192 href="http://www.gobosoft.com"><font size="2">//www.gobosoft.com</font></a><font
193 size="2"><br>
194 <strong>Last Updated:</strong> 13 February 2008</font><br>
195 <!--webbot bot="PurpleText"
196 preview="
197 $Date$
198 $Revision$"
199 -->
200 </address>
201 </td>
202 <td align="right" valign="top"><a
203 href="http://www.gobosoft.com"><img
204 src="../image/home.gif" alt="Home" border="0" width="40"
205 height="40"></a><a href="index.html"><img
206 src="../image/toc.gif" alt="Toc" border="0" width="40"
207 height="40"></a><a href="examples.html"><img
208 src="../image/previous.gif" alt="Previous" border="0"
209 width="40" height="40"></a><a href="configuration.html"><img
210 src="../image/next.gif" alt="Next" border="0" width="40"
211 height="40"></a></td>
212 </tr>
213 </table>
214 </body>
215 </html>

Properties

Name Value
svn:mime-type text/xml

  ViewVC Help
Powered by ViewVC 1.1.23