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

Contents of /vendor/gobosoft.com/gobo/current/doc/getest/examples.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: 8966 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: Some Simple Examples</title>
9 </head>
10
11 <body bgcolor="#FFFFFF">
12
13 <table border="0" width="100%">
14 <tr>
15 <td><font size="6"><strong>Some Simple Examples</strong></font></td>
16 <td align="right"><a href="stages.html"><img
17 src="../image/previous.gif" alt="Previous" border="0"
18 width="40" height="40"></a><a href="assertions.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>First some simple examples to get the flavor of how one uses <em>getest</em>:
27 let's consider a class with a function that concatenates two
28 strings and returns the result. This example is simple, but <em>getest
29 </em>works the same way for testing more realistic classes. </p>
30
31 <blockquote>
32 <pre><font color="#000080"><em><strong>class</strong></em></font><em> CONCAT1
33
34 </em><font color="#000080"><em><strong>create</strong></em></font><em>
35
36 make
37
38 </em><font color="#000080"><em><strong>feature</strong></em></font><em> </em>{<em>NONE</em>}<em> </em><font
39 color="#008000">-- Initialization</font><em>
40
41 make
42 </em><font color="#008000">-- Create a new string concatenator.</font><em>
43 </em><font color="#000080"><em><strong>do
44 end</strong></em></font><em>
45
46 </em><font color="#000080"><em><strong>feature</strong></em></font><em> </em><font
47 color="#008000">-- Basic operations</font><em>
48
49 concat </em>(<em>s1</em>,<em> s2</em>:<em> STRING</em>):<em> STRING
50 </em><font color="#008000">-- Concatenate </font><em>s1</em><font
51 color="#008000"> and </font><em>s2</em><font color="#008000">.</font><em>
52 </em><font color="#000080"><em><strong> require</strong></em></font><em>
53 s1_not_void</em>:<em> s1 </em>/=<em> </em><font
54 color="#008080"><em>Void</em></font><em>
55 s2_not_void</em>:<em> s2 </em>/=<em> </em><font
56 color="#008080"><em>Void</em></font><em>
57 </em><font color="#000080"><em><strong>do</strong></em></font><em>
58 </em><font color="#000080"><em><strong>create</strong></em></font><em> </em><font
59 color="#008080"><em>Result</em></font>.<em>make </em>(<em>s1</em>.<em>count </em>+<em> s2</em>.<em>count</em>)<em>
60 </em><font color="#008080"><em>Result</em></font>.<em>append_string </em>(<em>s1</em>)<em>
61 </em><font color="#008080"><em>Result</em></font>.<em>append_string </em>(<em>s1</em>)<em>
62 </em><font color="#000080"><em><strong>ensure</strong></em></font><em>
63 concat_string_not_void: </em><font color="#008080"><em>Result</em></font><em> </em>/=<em> </em><font
64 color="#008080"><em>Void</em></font><em>
65 </em><font color="#000080"><em><strong> end</strong></em></font><em>
66
67 </em><font color="#000080"><em><strong>end</strong></em></font><em> </em></pre>
68 </blockquote>
69
70 <p>In order to test this class, one just has to write a simple
71 test case. The test case class will inherit from class <font
72 color="#008080"><em><tt>TS_TEST_CASE</tt></em></font> (from the
73 test harness cluster of the <em>Gobo Eiffel Test Library</em>)
74 which will provide testing facilities to exercise Eiffel code,
75 such as routines <font color="#008080"><em><tt>assert</tt></em></font>
76 and <font color="#008080"><em><tt>assert_equal</tt></em></font>.
77 The test class will be equipped with a test routine <font
78 color="#008080"><em><tt>test_concat</tt></em></font> which makes
79 several assertions about the expected results of the feature <font
80 color="#008080"><em><tt>concat</tt></em></font> from the tested
81 class. </p>
82
83 <blockquote>
84 <pre><font color="#000080"><em><strong>class</strong></em></font><em> TEST_CONCAT1
85
86 </em><font color="#000080"><em><strong>inherit</strong></em></font><em>
87
88 TS_TEST_CASE
89
90 </em><font color="#000080"><em><strong>create</strong></em></font><em>
91
92 make_default
93
94 </em><font color="#000080"><em><strong>feature</strong></em></font><em> </em><font
95 color="#008000">-- Test</font><em>
96
97 test_concat
98 </em><font color="#008000">-- Test feature </font><em>concat</em><font
99 color="#008000">.</font><em>
100 </em><font color="#000080"><em><strong>local</strong></em></font><em>
101 c</em>:<em> CONCAT1
102 </em><font color="#000080"><em><strong>do</strong></em></font><em>
103 </em><font color="#000080"><em><strong>create</strong></em></font><em> c</em>.<em>make
104 assert_equal </em>(<font color="#800000"><em>&quot;toto&quot;</em></font>,<em> </em><font
105 color="#800000"><em>&quot;toto&quot;</em></font>,<em> c</em>.<em>concat </em>(<font
106 color="#800000"><em>&quot;to&quot;</em></font>,<em> </em><font
107 color="#800000"><em>&quot;to&quot;</em></font>))<em>
108 assert_equal </em>(<font color="#800000"><em>&quot;foobar&quot;</em></font>,<em> </em><font
109 color="#800000"><em>&quot;foobar&quot;</em></font>,<em> c</em>.<em>concat </em>(<font
110 color="#800000"><em>&quot;foo&quot;</em></font>,<em> </em><font
111 color="#800000"><em>&quot;bar&quot;</em></font>))<em>
112 </em><font color="#000080"><em><strong>end</strong></em></font><em>
113
114 </em><font color="#000080"><em><strong>end</strong></em></font><em> </em></pre>
115 </blockquote>
116
117 <p>The source code for this example can be found in <font
118 color="#800000"><tt>$GOBO/example/test/concat1</tt></font>.</p>
119
120 <p>Once this test case class has been written, one can run the
121 test suite as follows:</p>
122
123 <blockquote>
124 <pre><font color="#800000">getest getest.&lt;<em>compiler</em>&gt;</font></pre>
125 </blockquote>
126
127 <p>where <font color="#800000"><tt>&lt;</tt><em><tt>compiler</tt></em><tt>&gt;</tt></font>
128 is either <font color="#800000"><tt>ge</tt></font>, <font
129 color="#800000"><tt>ise</tt></font> or <font color="#800000"><tt>se</tt></font>
130 depending on the Eiffel compiler used to compile the test suite.
131 Alternatively one can use the following shorthand:</p>
132
133 <blockquote>
134 <pre><font color="#800000">getest --&lt;<em>compiler</em>&gt;</font></pre>
135 </blockquote>
136
137 <p>which is equivalent to the command-line above. Here is the
138 output I got when running <em>getest</em> with the ISE Eiffel
139 compiler:</p>
140
141 <blockquote>
142 <pre><font color="#800000">$ cd $GOBO/example/test/concat1
143 $ getest --ise
144 Preparing Test Cases
145 Compiling Test Cases
146 Running Test Cases
147
148 Test Summary for xconcat1
149
150 # Passed: 0 test
151 # FAILED: 1 test
152 # Aborted: 0 test
153 # Total: 1 test (2 assertions)
154
155 Test Results:
156 FAIL: [TEST_CONCAT1.test_concat] foobar
157 expected: foobar
158 but got: foofoo</font></pre>
159 </blockquote>
160
161 <p>Oh well, it looks like we have just found a bug! We can easily
162 see that the third line in the routine <font color="#008080"><em><tt>concat</tt></em></font>
163 from class <font color="#008080"><em><tt>CONCAT1</tt></em></font>
164 should have been:</p>
165
166 <blockquote>
167 <pre><font color="#008080"><em>Result</em></font>.<em>append_string </em>(<em>s2</em>)</pre>
168 </blockquote>
169
170 <p>The source code for this example with the bug fixed can be
171 found in <font color="#800000"><tt>$GOBO/example/test/concat2</tt></font>.
172 Here is what we get when we run <em>getest</em> again:</p>
173
174 <blockquote>
175 <pre><font color="#800000">$ cd $GOBO/example/test/concat2
176 $ getest --ise
177 Preparing Test Cases
178 Compiling Test Cases
179 Running Test Cases
180
181 Test Summary for xconcat2
182
183 # PASSED: 1 test
184 # Failed: 0 test
185 # Aborted: 0 test
186 # Total: 1 test (2 assertions)</font></pre>
187 </blockquote>
188
189 <p>That's better!</p>
190
191 <hr size="1">
192
193 <table border="0" width="100%">
194 <tr>
195 <td><address>
196 <font size="2"><b>Copyright 2001-2008</b></font><font
197 size="1"><b>, </b></font><font size="2"><strong>Eric
198 Bezault</strong></font><strong> </strong><font
199 size="2"><br>
200 <strong>mailto:</strong></font><a
201 href="mailto:ericb@gobosoft.com"><font size="2">ericb@gobosoft.com</font></a><font
202 size="2"> <br>
203 <strong>http:</strong></font><a
204 href="http://www.gobosoft.com"><font size="2">//www.gobosoft.com</font></a><font
205 size="2"><br>
206 <strong>Last Updated:</strong> 13 February 2008</font><br>
207 <!--webbot bot="PurpleText"
208 preview="
209 $Date$
210 $Revision$"
211 -->
212 </address>
213 </td>
214 <td align="right" valign="top"><a
215 href="http://www.gobosoft.com"><img
216 src="../image/home.gif" alt="Home" border="0" width="40"
217 height="40"></a><a href="index.html"><img
218 src="../image/toc.gif" alt="Toc" border="0" width="40"
219 height="40"></a><a href="stages.html"><img
220 src="../image/previous.gif" alt="Previous" border="0"
221 width="40" height="40"></a><a href="assertions.html"><img
222 src="../image/next.gif" alt="Next" border="0" width="40"
223 height="40"></a></td>
224 </tr>
225 </table>
226 </body>
227 </html>

Properties

Name Value
svn:mime-type text/xml

  ViewVC Help
Powered by ViewVC 1.1.23