Sunday, 16 August 2009

Testing on the Bog - Pushing the Boundaries

PDF version for placing in your office.

What is Testing on the Bog?

Code has “if” statements in it. When testing you need to check that the different conditions of the if statement. Lets take the following code snippet

if input_date <= current_date:
echo 'Date not in the future'
echo 'Date in the future'

The obvious values to test is a date less than or equal to today and one in the future. Test with 2009-08-08 and 2009-08-29 would give you 100% statement and branch coverage when you get your coverage statistics from your unit tests. Well that was easy wasn't it?

“High Code Coverage” ≠ “Well tested Code”

Firstly it is “<=” so both the “<” and the “=” need to be tested separately. Also mentioned in the previous Testing on the Bog dates can be complicated beast as well.

So looking at the clear boundaries to test there are also the not so obvious ones. An example of this could be:
  • Time is often stored as an integer and only formated in the interface layer, so can you put in a date which so big that it wraps the integer around and it becomes less than the current date? And the flip so negative this get confused as well?
The explicit boundaries, which are normally documented as functional requirements, are generally ok to find it is the other ones, which may be non functional requirements or just not documented at all, that aren't obvious which will catch you out some of the time. It is impossible to think of every boundary along the way but just remember you have to look beyond of the obvious ones. Some of these may seem a bit crazy but what users will input into a system can some of the time be very bizzare.