Tests often establish example values used to compare the behavior of the system with the actual behavior indicated in the requirements. For example, if we had a system behavior that converted a temperature expressed in Fahrenheit to one expressed in Celsius, then the test that specified this might have an assertion along these lines:
However the use of these values directly in the assertion sidesteps an opportunity to express the meaning of those values in the specification. Why did we choose 212 and 100, specifically? If there is a reason, then we would want to capture that information as well, in order to form a more complete specification.
The creation of temporary variables, sometimes called “instrumented values” creates this opportunity. For example:
int boilingPointFahrenheit = 212; int boilingPointCelsius = 100; assertEquals(boilingPointCelsius, converter.fahrenheitToCelsius(boilingPointFahrenheit));
This not only captures the semantics of the test more completely, but also helps to create the separation of Given/Setup (the instrument is part of this) from the When/Trigger (the calling of the indicated method).
This also makes the test more readable as a specification.
This is Scott Bain. Visit us at www.netobjectives.com.