Posts about testing

Unit Testing Redux

Thinking back over my post from a year ago, I find that the real reason for most bad unit tests is that people are trying too hard, typically for one of the following reasons:

  • Some folks have drunk the "don't repeat yourself" KoolAid: I agree that not repeating code is a virtue in most cases, but unit test code is an exception: cleverness in a test both obscures the intent of the test and makes a subsequent failure massively harder to diagnose.

  • Others want to avoid writing both tests and documentation: they try to write test cases (almost invariably as "doctests") which do the work of real tests, while at the same time trying to make "readable" docs.

Read more…

Avoiding Temptation: Notes on using 'unittest' effectively

Avoiding Temptation: Notes on using 'unittest' effectively

Goals

The goals of the kind of testing outlined here are simplicity, loose or no coupling, and speed:

  • Tests should be as simple as possible, while exercising the application- under-test (AUT) completely.
  • Tests should run as quickly as possible, to encourage running them frequently.
  • Tests should avoid coupling with other tests, or with parts of the AUT which they are not responsible for testing.

Developers write such tests to verify that the AUT is abiding by the contracts the developer specifies. While an instance this type of test case may be illustrative of the contract it tests, such test cases do not take the place of either API documentation or of narrative / "theory of operations" documentation. Still less are they intended for end-user documentation.

Read more…