Feed on

I would like to offer the agile and XP communities a new word for an old idea:  Microtest instead of Unit Test.

My rationale for this suggestion is straightforward. Unit test already has a meaning out there in the development world, and that meaning doesn’t match the agile/XP meaning.  There are several aspects of an ordinary microtest that can be entirely absent from a normal unit test.  Traveling around as I do, I get to work with an enormous number of teams, and I can tell you from extensive experience, teaching people about XP style testing is notably easier when we don’t have to repurpose a word that’s already in play.

A microtest has the following properties:

  • It is short, typically under a dozen lines of code.
  • It is always automated.
  • It does not test the object inside the running app, but instead in a purpose-built testing application.
  • It invokes only a tiny portion of the code, most usually a single branch of a single function.
  • It is written gray-box, i.e. it reads as if it were black-box, but sometimes takes advantage of white-box knowledge.  (Typically a critical factor in avoiding combinatoric issues.)
  • It is coded to the same standard as shipping code, i.e. the team’s best current understanding of coding excellence. 
  • It is vault-committed source, with a lifetime co-terminous with the functionality it tests.
  • In combination with all other microtests of an app, it serves as a ‘gateway-to-commit’.  That is, a developer is encouraged to commit anytime all microtests run green, and discouraged (strongly, even nastily) to commit otherwise.
  • It takes complete control of the object-under-test and is therefore self-contained, i.e. running with no dependencies on anything other than the testing code and its dependency graph.
  • It runs in an extremely short time, milliseconds per test.
  • It provides precise feedback on any errors that it encounters.
  • It usually (not always) runs entirely inside a single computer.
  • It usually (not always) runs entirely inside a single process, i.e. with few extra-process runtime dependencies.
  • It is part of a collection all or any subset of which is invokable with a single programmer gesture.
  • It is written before the code-change it is meant to test.
  • It avoids most or all usage of ‘awkward’ collaborators via a variety of slip-and-fake techniques.
  • It rarely involves construction of more than a few classes of object, often one or two, usually under five.

Over the years I’ve had some pretty comedic conversations with people.  One fellow was quite irate and insisted that the list above was just the definition of a good unit test.  Maybe microtest just means good unit test.

17 Responses to “They’re Called Microtests”

  1. Marcie says:

    Great idea. I’ve run across a lot of people who say “yes, of course we unit test.”, but they don’t mean what I mean.

  2. […] You discover some subtle variations or edge cases in the scenario that would not interest the customer, or will be hard to write an acceptance test for, but will need to be dealt with to make the product robust. Listen to your boredom: Now it’s time to drop down and write a unit test. Or should I say microtest? […]

  3. Gavin says:

    Will an example of the differences be possible?
    Would this be considered a microtest?

    Say I create a “Microtest” where I instantiate a message handler. The message handler reads the message, obviously, and finds all expired library books and flags them as expired.

    All database and external dependencies are mocked or faked out.
    Is this considered a Microtest or Unit test or is this example to vague. The test checks that an expired book is flagged as ‘Expired’.

    P.S. Sorry to use the old Library example.

    • GeePawHill says:

      Gavin, what you’ve described seems very much a microtest. (I may roll a few examples in the code project i’m getting ready to offer here.) — Hill

  4. Why not just call them “examples?”

    • Stephan says:

      As far as I am concerned an example demonstrates that (or how) something does work.
      In contrast, a test is meant to show that something doesn’t work (as expected) – in the first place. Of course having a large set of passing tests gives some confidence of working software.
      (I don’t think the two are opposites of each other, but they’re certainly not the same either.)

  5. […] Because that’s what I want. I will wrestle with it, in public, until I have brought it under microtest. […]

  6. Darren Rowley says:

    I like this, I always used to say – just because it extends JUnit doesn’t mean its a unit test.

  7. jim says:

    Isn’t this term already in use?

  8. […] Write tests before writing the code. It helps to be more clear about the requirements and help to focus the programming efforts. In software development typing is never the bottleneck. Thinking is. Tests make development faster because they help to focus: “How TDD and Pairing Increase Production” and “They’re Called Microtests” […]

  9. GeePawHill says:

    Thx! Fixed it. (I *do* wish I could keep comments on the same page as the article. sigh.)

  10. Josh says:

    I really like this list. I often get frustrated in interviews or when talking to other people about unit testing because I always have to qualify what I mean. I usually make a big deal about the difference between a Unit Test and Acceptance/Integration test because it is so critical.

    Most of the time when I encounter teams that are weary about TDD it is because their idea of a Unit Test is what I think of as an Acceptance Test. I often get met with great hostility when I try to tell someone that if their “unit test” requires external dependencies (database, web service, file system) then it isn’t really a unit test.

    I am going to start using this term. I don’t think it will reduce the amount explaining I have to do, but at least I will be starting with a clean slate :)

  11. Octavian Ciubotaru says:

    The concept of microtest appeared because unit test frameworks were used for all kinds of tests. In my opinion unit test frameworks are misused.

Leave a Reply

AWSOM Powered