Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<html>
2
<head>
3
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
4
<title>
5
        Overview and feature list for the SimpleTest PHP unit tester and web tester
6
    </title>
7
<link rel="stylesheet" type="text/css" href="docs.css" title="Styles">
8
</head>
9
<body>
10
<div class="menu_back">
11
<div class="menu">
12
<h2>
13
<a href="index.html">SimpleTest</a>
14
</h2>
15
<ul>
16
<li>
17
<span class="chosen">Overview</span>
18
</li>
19
<li>
20
<a href="unit_test_documentation.html">Unit tester</a>
21
</li>
22
<li>
23
<a href="group_test_documentation.html">Group tests</a>
24
</li>
25
<li>
26
<a href="mock_objects_documentation.html">Mock objects</a>
27
</li>
28
<li>
29
<a href="partial_mocks_documentation.html">Partial mocks</a>
30
</li>
31
<li>
32
<a href="reporter_documentation.html">Reporting</a>
33
</li>
34
<li>
35
<a href="expectation_documentation.html">Expectations</a>
36
</li>
37
<li>
38
<a href="web_tester_documentation.html">Web tester</a>
39
</li>
40
<li>
41
<a href="form_testing_documentation.html">Testing forms</a>
42
</li>
43
<li>
44
<a href="authentication_documentation.html">Authentication</a>
45
</li>
46
<li>
47
<a href="browser_documentation.html">Scriptable browser</a>
48
</li>
49
</ul>
50
</div>
51
</div>
52
<h1>Overview of SimpleTest</h1>
53
<div class="content">
54
        <p>
55
<a class="target" name="summary">
56
<h2>What is SimpleTest?</h2>
57
</a>
58
</p>
59
            <p>
60
                The heart of SimpleTest is a testing framework built around
61
                test case classes.
62
                These are written as extensions of base test case classes,
63
                each extended with methods that actually contain test code.
64
                Top level test scripts then invoke the <span class="new_code">run()</span>
65
                methods on every one of these test cases in order.
66
                Each test method is written to invoke various assertions that
67
                the developer expects to be true such as
68
                <span class="new_code">assertEqual()</span>.
69
                If the expectation is correct, then a successful result is dispatched to the
70
                observing test reporter, but any failure triggers an alert
71
                and a description of the mismatch.
72
            </p>
73
            <p>
74
                A <a href="unit_test_documentation.html">test case</a> looks like this...
75
<pre>
76
&lt;?php
77
class <strong>MyTestCase</strong> extends UnitTestCase {
78
    <strong>
79
    function testLog() {
80
        $log = &amp;new Log('my.log');
81
        $log-&gt;message('Hello');
82
        $this-&gt;assertTrue(file_exists('my.log'));
83
    }</strong>
84
}
85
?&gt;
86
</pre>
87
            </p>
88
            <p>
89
                These tools are designed for the developer.
90
                Tests are written in the PHP language itself more or less
91
                as the application itself is built.
92
                The advantage of using PHP itself as the testing language is that
93
                there are no new languages to learn, testing can start straight away,
94
                and the developer can test any part of the code.
95
                Basically, all parts that can be accessed by the application code can also be
96
                accessed by the test code if they are in the same language.
97
            </p>
98
            <p>
99
                The simplest type of test case is the
100
                <a href="unit_tester_documentation.html">UnitTestCase</a>.
101
                This class of test case includes standard tests for equality,
102
                references and pattern matching.
103
                All these test the typical expectations of what you would
104
                expect the result of a function or method to be.
105
                This is by far the most common type of test in the daily
106
                routine of development, making up about 95% of test cases.
107
            </p>
108
            <p>
109
                The top level task of a web application though is not to
110
                produce correct output from its methods and objects, but
111
                to generate web pages.
112
                The <a href="web_tester_documentation.html">WebTestCase</a> class tests web
113
                pages.
114
                It simulates a web browser requesting a page, complete with
115
                cookies, proxies, secure connections, authentication, forms, frames and most
116
                navigation elements.
117
                With this type of test case, the developer can assert that
118
                information is present in the page and that forms and
119
                sessions are handled correctly.
120
            </p>
121
            <p>
122
                A <a href="web_tester_documentation.html">WebTestCase</a> looks like this...
123
<pre>
124
&lt;?php
125
class <strong>MySiteTest</strong> extends WebTestCase {
126
    <strong>
127
    function testHomePage() {
128
        $this-&gt;get('http://www.my-site.com/index.php');
129
        $this-&gt;assertTitle('My Home Page');
130
        $this-&gt;clickLink('Contact');
131
        $this-&gt;assertTitle('Contact me');
132
        $this-&gt;assertWantedPattern('/Email me at/');
133
    }</strong>
134
}
135
?&gt;
136
</pre>
137
            </p>
138
 
139
        <p>
140
<a class="target" name="features">
141
<h2>Feature list</h2>
142
</a>
143
</p>
144
            <p>
145
                The following is a very rough outline of past and future features
146
                and their expected point of release.
147
                I am afraid it is liable to change without warning as meeting the
148
                milestones rather depends on time available.
149
                Green stuff has been coded, but not necessarily released yet.
150
                If you have a pressing need for a green but unreleased feature
151
                then you should check-out the code from Sourceforge CVS directly.
152
                <table>
153
<thead>
154
                    <tr>
155
<th>Feature</th><th>Description</th><th>Release</th>
156
</tr>
157
                    </thead>
158
<tbody>
159
<tr>
160
                        <td>Unit test case</td>
161
                        <td>Core test case class and assertions</td>
162
                        <td style="color: green;">1.0</td>
163
                    </tr>
164
                    <tr>
165
                        <td>Html display</td>
166
                        <td>Simplest possible display</td>
167
                        <td style="color: green;">1.0</td>
168
                    </tr>
169
                    <tr>
170
                        <td>Autoloading of test cases</td>
171
                        <td>
172
                            Reading a file with test cases and loading them into a
173
                            group test automatically
174
                        </td>
175
                        <td style="color: green;">1.0</td>
176
                    </tr>
177
                    <tr>
178
                        <td>Mock objects</td>
179
                        <td>
180
                            Objects capable of simulating other objects removing
181
                            test dependencies
182
                        </td>
183
                        <td style="color: green;">1.0</td>
184
                    </tr>
185
                    <tr>
186
                        <td>Web test case</td>
187
                        <td>Allows link following and title tag matching</td>
188
                        <td style="color: green;">1.0</td>
189
                    </tr>
190
                    <tr>
191
                        <td>Partial mocks</td>
192
                        <td>
193
                            Mocking parts of a class for testing less than a class
194
                            or for complex simulations
195
                        </td>
196
                        <td style="color: green;">1.0</td>
197
                    </tr>
198
                    <tr>
199
                        <td>Web cookie handling</td>
200
                        <td>Correct handling of cookies when fetching pages</td>
201
                        <td style="color: green;">1.0</td>
202
                    </tr>
203
                    <tr>
204
                        <td>Following redirects</td>
205
                        <td>Page fetching automatically follows 300 redirects</td>
206
                        <td style="color: green;">1.0</td>
207
                    </tr>
208
                    <tr>
209
                        <td>Form parsing</td>
210
                        <td>Ability to submit simple forms and read default form values</td>
211
                        <td style="color: green;">1.0</td>
212
                    </tr>
213
                    <tr>
214
                        <td>Command line interface</td>
215
                        <td>Test display without the need of a web browser</td>
216
                        <td style="color: green;">1.0</td>
217
                    </tr>
218
                    <tr>
219
                        <td>Exposure of expectation classes</td>
220
                        <td>Can create precise tests with mocks as well as test cases</td>
221
                        <td style="color: green;">1.0</td>
222
                    </tr>
223
                    <tr>
224
                        <td>XML output and parsing</td>
225
                        <td>
226
                            Allows multi host testing and the integration of acceptance
227
                            testing extensions
228
                        </td>
229
                        <td style="color: green;">1.0</td>
230
                    </tr>
231
                    <tr>
232
                        <td>Browser component</td>
233
                        <td>
234
                            Exposure of lower level web browser interface for more
235
                            detailed test cases
236
                        </td>
237
                        <td style="color: green;">1.0</td>
238
                    </tr>
239
                    <tr>
240
                        <td>HTTP authentication</td>
241
                        <td>
242
                            Fetching protected web pages with basic authentication
243
                            only
244
                        </td>
245
                        <td style="color: green;">1.0</td>
246
                    </tr>
247
                    <tr>
248
                        <td>SSL support</td>
249
                        <td>Can connect to https: pages</td>
250
                        <td style="color: green;">1.0</td>
251
                    </tr>
252
                    <tr>
253
                        <td>Proxy support</td>
254
                        <td>Can connect via. common proxies</td>
255
                        <td style="color: green;">1.0</td>
256
                    </tr>
257
                    <tr>
258
                        <td>Frames support</td>
259
                        <td>Handling of frames in web test cases</td>
260
                        <td style="color: green;">1.0</td>
261
                    </tr>
262
                    <tr>
263
                        <td>File upload testing</td>
264
                        <td>Can simulate the input type file tag</td>
265
                        <td style="color: green;">1.0.1</td>
266
                    </tr>
267
                    <tr>
268
                        <td>Mocking interfaces</td>
269
                        <td>
270
                            Can generate mock objects to interfaces as well as classes
271
                            and class interfaces are carried for type hints
272
                        </td>
273
                        <td style="color: green;">1.0.1</td>
274
                    </tr>
275
                    <tr>
276
                        <td>Reporting machinery enhancements</td>
277
                        <td>Improved message passing for better cooperation with IDEs</td>
278
                        <td style="color: red;">1.1</td>
279
                    </tr>
280
                    <tr>
281
                        <td>Localisation</td>
282
                        <td>Messages abstracted and code generated from XML</td>
283
                        <td style="color: red;">1.1</td>
284
                    </tr>
285
                    <tr>
286
                        <td>Testing exceptions</td>
287
                        <td>Similar to testing PHP errors</td>
288
                        <td style="color: red;">1.1</td>
289
                    </tr>
290
                    <tr>
291
                        <td>IFrame support</td>
292
                        <td>Reads IFrame content that can be refreshed</td>
293
                        <td style="color: red;">1.1</td>
294
                    </tr>
295
                    <tr>
296
                        <td>Improved mock interface</td>
297
                        <td>More compact way of expressing mocks</td>
298
                        <td style="color: red;">2.0</td>
299
                    </tr>
300
                    <tr>
301
                        <td>HTML table assertions</td>
302
                        <td>Can match table elements to numerical assertions</td>
303
                        <td style="color: red;">2.0</td>
304
                    </tr>
305
                    <tr>
306
                        <td>XPath searching of HTML elements</td>
307
                        <td>More flexible content matching</td>
308
                        <td style="color: red;">2.0</td>
309
                    </tr>
310
                    <tr>
311
                        <td>Alternate HTML parsers</td>
312
                        <td>Can detect compiled parsers for performance improvements</td>
313
                        <td style="color: red;">2.0</td>
314
                    </tr>
315
                    <tr>
316
                        <td>Javascript suport</td>
317
                        <td>Use of PECL module to add Javascript</td>
318
                        <td style="color: red;">3.0</td>
319
                    </tr>
320
                </tbody>
321
</table>
322
                PHP5 migraton will start straight after the version 1.0.1 series,
323
                whereupon PHP4 will no longer be supported.
324
                SimpleTest is currently compatible with PHP5, but will not
325
                make use of all of the new features until version 2.
326
            </p>
327
 
328
        <p>
329
<a class="target" name="resources">
330
<h2>Web resources for testing</h2>
331
</a>
332
</p>
333
            <p>
334
                Process is at least as important as tools.
335
                The type of process that makes the heaviest use of a developer's
336
                testing tool is of course
337
                <a href="http://www.extremeprogramming.org/">Extreme Programming</a>.
338
                This is one of the
339
                <a href="http://www.agilealliance.com/articles/index">Agile Methodologies</a>
340
                which combine various practices to "flatten the cost curve" of software development.
341
                More extreme still is <a href="http://www.testdriven.com/modules/news/">Test Driven Development</a>,
342
                where you very strictly adhere to the rule of no coding until you have a test.
343
                If you're more of a planner or believe that experience trumps evolution,
344
                you may prefer the
345
                <a href="http://www.therationaledge.com/content/dec_01/f_spiritOfTheRUP_pk.html">RUP</a> approach.
346
                I haven't tried it, but even I can see that you will need test tools (see figure 9).
347
            </p>
348
            <p>
349
                Most unit testers clone <a href="http://www.junit.org/">JUnit</a> to some degree,
350
                as far as the interface at least. There is a wealth of information on the
351
                JUnit site including the
352
                <a href="http://junit.sourceforge.net/doc/faq/faq.htm">FAQ</a>
353
                which contains plenty of general advice on testing.
354
                Once you get bitten by the bug you will certainly appreciate the phrase
355
                <a href="http://junit.sourceforge.net/doc/testinfected/testing.htm">test infected</a>
356
                coined by Eric Gamma.
357
                If you are still reviewing which unit tester to use the main choices
358
                are <a href="http://phpunit.sourceforge.net/">PHPUnit</a>
359
                and <a href="http://pear.php.net/manual/en/package.php.phpunit.php">Pear PHP::PHPUnit</a>.
360
                They currently lack a lot of features found in
361
                <a href="http://www.lastcraft.com/simple_test.php">SimpleTest</a>, but the PEAR
362
                version at least has been upgraded for PHP5 and is recommended if you are porting
363
                existing <a href="http://www.junit.org/">JUnit</a> test cases.
364
            </p>
365
            <p>
366
                There is currently a sad lack of material on mock objects, which is a shame
367
                as unit testing without them is a lot more work.
368
                The <a href="http://www.sidewize.com/company/mockobjects.pdf">original mock objects paper</a>
369
                is very Java focused, but still worth a read.
370
                As a new technology there are plenty of discussions and debate on how to use mocks,
371
                often on Wikis such as
372
                <a href="http://xpdeveloper.com/cgi-bin/oldwiki.cgi?MockObjects">Extreme Tuesday</a>
373
                or <a href="http://www.mockobjects.com/MocksObjectsPaper.html">www.mockobjects.com</a>
374
                or <a href="http://c2.com/cgi/wiki?MockObject">the original C2 Wiki</a>.
375
                Injecting mocks into a class is the main area of debate for which this
376
                <a href="http://www-106.ibm.com/developerworks/java/library/j-mocktest.html">paper on IBM</a>
377
                makes a good starting point.
378
            </p>
379
            <p>
380
                There are plenty of web testing tools, but the scriptable ones
381
                are mostly are written in Java and
382
                tutorials and advice are rather thin on the ground.
383
                The only hope is to look at the documentation for
384
                <a href="http://httpunit.sourceforge.net/">HTTPUnit</a>,
385
                <a href="http://htmlunit.sourceforge.net/">HTMLUnit</a>
386
                or <a href="http://jwebunit.sourceforge.net/">JWebUnit</a> and hope for clues.
387
                There are some XML driven test frameworks, but again most
388
                require Java to run.
389
            </p>
390
            <p>
391
                A new generation of tools that run directly in the web browser
392
                are now available.
393
                These include
394
                <a href="http://www.openqa.org/selenium/">Selenium</a> and
395
                <a href="http://wtr.rubyforge.org/">Watir</a>.
396
                As SimpleTest does not support JavaScript you would probably
397
                have to look at these tools anyway if you have highly dynamic
398
                pages.
399
            </p>
400
 
401
    </div>
402
<div class="copyright">
403
            Copyright<br>Marcus Baker, Jason Sweat, Perrick Penet 2004
404
        </div>
405
</body>
406
</html>