Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Jani Hartikainen's Blog:
Unit testing 5: test-driven development
Jul 06, 2009 @ 22:06:27

Jani Hartikainen has posted part five of his look at unit testing in PHP (with PHPUnit) focusing on test-driven development.

The difference between “normal” and test-driven development (TDD) is that when doing TDD, you write unit tests for your new code before writing the code itself. This way you ensure good test coverage for your code, and your code will also be more flexible and reusable, as you have to design the class interfaces for easy testing.

He looks at some of the basics - like preconditions and postconditions - and how to create the tests for your application before you write a single line of (non-test) code. His examples show evaluations for testing for an empty order and to see if an object has an item in it after it's been added.

tagged: tutorial testdrivendevelopment tdd unittest