.
Developer Spot - Web Development Tutorials
 


Web Hosting Directory
Budget Web Hosting Linux Web Hosting Small Business Hosting
Windows Web Hosting Reseller Web Hosting Web Hosting Articles

Test Driven Development

By Marcus Baker
2004-01-25
Reader Rating: 5 out of 5
Bookmark Print Version
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.





Article Pages:
Test Driven Development
Writing a Test
A Simple Test Case
Our first test (at last)
Minimal Code
Design with working tests
Tests as documentation
Test then Code then Design

 Rate this article:   Poor          Excellent 


If you found this article interesting, you may want to read these as well:

» Protecting your PHP and HTML Source Code

» Publishing Newsletters Using PHP & MySQL - 4

» Publishing Newsletters Using PHP & MySQL - 3

» Publishing Newsletter Using PHP & MySQL - 2

» Publishing Newsletters Using PHP & MySQL

» Unix Webserver Crontab Basics



 
Development Tutorials
ASP
CGI & Perl
CSS
HTML
Java
JavaScript
Linux
PHP
XML




More Resources
Web Hosting Articles
Development Tutorials: CGI & Perl - CSS - HTML - Java - JavaScript - Linux - PHP - XML