PHPBuilder - Test Driven Development in PHP Page 3

RSS Twitter
Articles Application Architecture

Test Driven Development in PHP - Page 3

by: Marcus Baker
February 3, 2004

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...

SIMPLE_TEST 'unit_tester.php');
SIMPLE_TEST 'reporter.php');

ConfigurationTest extends UnitTestCase {
ConfigurationTest() {

$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...


1/1 test cases complete: 0 passes, 0 fails and 0 exceptions.
Having got our environment set up you probably think we are ready to code. If so, give yourself a slap on the wrist! We are actually ready to write our first test.

« Previous Page
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Marcus Baker



(Maximum characters: 1200). You have characters left.