Online. Offline. Bottom Line.™ (skip to the content)

Home | About | Jobs | Privacy Policy | Contact | Login or Register


Amazing What a Little Unit Testing Can Do…

by

I recently received an email from a colleague about a particular issue they encountered, and I couldn’t help but share.  This engineer was working on the second version of a project that had been released about two years prior.  The original author of the code apparently did not subscribe to the idea of unit tests, because there was no test suite at all.  Now, two years after the initial release, my colleague is adding tests and discovering that some features simply never worked to begin with…

In the project my colleague was working on, one of the features was an export of data over a specified date range.  The data query was simple enough, one that any junior developer would have been able to do.  But because my colleague was making a slight change to the function that used the query, he did what any good engineer should do and created some unit tests to test the function.  Imagine his surprise when none of the tests passed.  So he looked into the pre-existing code a little bit and it didn’t take him long to find the problem.  In the query, both a start date and a stop date were being passed… but they had been inadvertently reversed! The query worked fine if no dates were specified because it just returned all rows.  However if one or both dates were specified, incorrect data was returned.  If just the start date was specified, it returned all data processed before that date.  If just the end date was specified, it returned all data processed after that date.  If both dates were specified, no rows were returned.

It took my colleague less than ten minutes to catch his incredibly simple - yet serious - bug.  Yet because the original author chose not to unit test, it was not detected until two years after release.  To make matters worse, the problem with the exports was noticed by the end users almost immediately.  But instead of reporting it, they simply stopped using that particular feature.  An entire piece of functionality was essentially removed from the application just because two dates were swapped in a database query.

Amazing what a little unit testing can do for an application.  Even when you think that the unit being tested is too simple to break…

Found in • (0) CommentsPermalink http://www.sundog.net/index.php/sunblog/entry/unit-tests-versus-user-acceptance-testing/
Like this post? Subscribe to our RSS feed. RSS icon

© 2008 Sundog, All Rights Reserved xhtml | css | 508 | What's This?