Mike On Software: What makes a good unit test?What makes a good unit test? There are as many definitions as there are programmers, but as far as I'm concerned, a good unit test can be determined by just two characteristics: it runs fast; and when it fails, it points you to a small section of code.
Many people mention other characteristics: your unit tests should isolate the unit under test, have a limited scope, run isolated from other libraries, etc. But these concerns really only matter to the extent that they help your test run faster, and help you focus on a small section of code. Anything else is a distraction. Heck, even if your unit test includes every library on the system, it can still be a great unit test... as long as it remains fast and focused.
Conversely, I've seen "unit tests" that attempt to isolate the code being tested, jump through hoops to have no external dependencies, and so on, but they were no good, because they took forever to run, or did not have any ability to focus failures on small blocks of code.
Don't get confused between the technique and the goal. If your unit test runs fast and does a good job of scoping test failures, you're done.
Tags: software, testing, programming, unit tests, unit test, agile programming