It is often tempting to skip unit testing for ad-hoc testing. However when done in the appropriate amount unit testing will increase productivity and reliability. It is also a great diagnostic tool. Unit testing is a skill that can get you to the next level as a programmer as well as an organization. It takes discipline and when done in the right amount you should be able to reap the benefits in weeks.
In this article, I will show simple examples on how to move your ad-hoc tests to test classes. The examples use the RawDev framework which makes unit testing as easy as it can possibly be. I will cover what a unit test is, how to create tests and a tool to execute the tests. I will also talk about some of the pitfalls and how to get around them.
What is a unit test?
Since virtually all code resides in functions, RawDev uses the following definition:
RawDev defines a unit test as a single test of the output of a function call, given specific input. Part of a test is also the verification of object and global state changes.
The above diagram shows all the relationships to a function that is unit tested. The terms in the diagram are described below:

Continue reading "It Is Not Whether You Should Unit Test But How Much" »



PHP5 Magazine's RSS
