Sunday, November 8, 2009

The Art of Unit Testing

As a Database Architect, I often work with Object-Oriented Programmers, but thankfully don’t often have to code in other languages other than SQL.  However, it is useful to understand the methods and basic frameworks by which my team members develop; hence, I decided to review Roy Osherove’s The Art of Unit Testing (Manning Press, 2009).  Although many of the examples in the latter half of the book were a little over my head, I do appreciate the fact that Osherove builds to that point in a simple, easy-to-follow manner.

The first chapter was particularly useful to me, because the author lays out some very basic criteria for defining a unit test, which I’ll paraphrase below:

  • Is the test repeatable after a period of time (years, months, etc?)
  • Is the test portable?  Can other team members run the same unit test?
  • Is the test simple to run?  Can it be run with the push of a button, and in just a few minutes?
  • Is the test simple to build?

If the answer to any of the previous questions is no, then you’re probably not doing a unit test; Osherove argues that you’re probably doing some form of integration testing, which may be useful, but is not a true unit test.  His argument for the art builds from there.

This book is very well laid out, with lots of examples (written in C#).  It’s a short read (under 300 pages, including indexes), and has a straightforward style that lends itself well to both the beginning programmer (or programmers from other traditions, like myself) all the way to experienced programmers who want to refresh their memory on basic concepts.

1 comment:

  1. Nice article and good book. you have indeed covered the book well.

    Thanks
    array and arraylist in java

    ReplyDelete