Helping ordinary people create extraordinary websites!

Test Driven Development

By Marcus Baker
2004-01-25

A Simple Test Case
Installing the SimpleTest unit tester is as simple as unpacking the tar file from sourceforge. To build some tests, however, we need to get a little bit organised. I am going to assume that the code is going into a folder called classes and that the test cases are going into a folder called test. Also we'll use a symlink, or path, to make SimpleTest available as test/simpletest.

If this is the case, we can write a do nothing test case (test/config_test.php) as follows...

<?php
define('SIMPLE_TEST', 'simpletest/');
require_once(SIMPLE_TEST . 'unit_tester.php');
require_once(SIMPLE_TEST . 'reporter.php');

class ConfigurationTest extends UnitTestCase {
     function ConfigurationTest() {
        $this->UnitTestCase();
    }
}

$test = &new ConfigurationTest();
$test->run(new HtmlReporter());
?>

The first block includes the files needed by the tester with the proviso that the SIMPLE_TEST constant must point at the SimpleTest directory. The second block is the actual test case, more on this in a minute. The third block creates the test case and runs it.

To keep things simple I have compressed the entire test suite into a single, rather cluttered, file. In the real world you would only need the actual test case, as the running and grouping of tests would be in a separate runner script.

If you point your web browser at the test script it will actually run successfully...

configurationtest


1/1 test cases complete:0 passes, 0 fails and 0 exceptions.





Tutorial pages:
 1 Votes

You might also want to check these out:


Leave a Comment on "Test Driven Development"
You must be logged in to post a comment.

Link to This Tutorial Page!


GET OUR NEWSLETTERS