Practice writing specific tests

  1. Specific, ie. the cause of failure is obvious from the test.
  2. Predictive, ie. no failure means all is good.


To help practice writing specific tests I have constructed a GitHub repo with nine different versions of the same function. They all look natural, but all have bugs, except for one. Sort of a Where’s Waldo but with bugs. The function has a fairly simple purpose:

  • find the average, and
  • subtract the average from each element.
  • A good test is specific — ie. fails as few implementations as possible. (Only one of my tests fail more than one implementation.)
  • A good test is correct — ie. never fails the working implementation.
  • A good suite should be complete — ie. fail all but the working implementation.

I live by my mentors words: “The key to being consistently brilliant is: hard work, every day.”

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store