Tuesday 27 October 2009

Naming unit tests

In his book The Art of Unit Testing, Roy Osherove suggests the following format for the name of unit tests:

MethodUnderTest_Scenario_Behaviour()

  • MethodUnderTest - The name of the method being tested.
  • Scenario - This part gives us the “with” part of the name: “When I call method X with a null value, then it should do Y.”
  • Behaviour - This part specifies in plain English what the method should do or return, or how it should behave, based on the current scenario: “When I call method X with a null value, then it should do Y.”