Maybe you thought that
test-driven development is restricted only to platforms like Java and .NET...I'll be happy to inform you that
PHP can also do that!
Here's my simplest test case using TDD on PHP:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <?php
require_once '../../simpletest/unit_tester.php'; require_once '../../simpletest/reporter.php';
class MyTestCase extends UnitTestCase { function MyTestCase() { $this->UnitTestCase('My test'); } function TestAdd() { $this->assertEqual(5, 2+3); } }
$test = &new MyTestCase(); $test->run(new HtmlReporter());
?> |
Running it in a web browser results in:
My test
1/1 test cases complete:
1 passes, 0 fails and 0 exceptions.
I'm using this testing framework for PHP called
SimpleTest. Somehow I prefer it to the one that got included in the
PEAR repository. It's even got mocking facilities too! Now I have no excuse not to do TDD on whatever environment I use...psst, is there any way I can do TDD on SQL?
Posted
08-29-2006 5:48 AM
by
cruizer