Back to the future TDD
Test written in November/2009:
@Test
premiumDisplayedForAShortTermPolicy() {
given(theBroker.hasStartedAQuoteWithMinimumDataToConvertToNewBusiness());
and(theBroker.enters.field(DUE_DATE, “15/12/2009″));
when(theBroker.underwrites());
then(thePolicy.hasCurrentMotorPremiumDisplayed());
}
The intent of DUE DATE was a date in a short future, less than a year. So, one month would be enough. That test broke on the 16/12/2009!!! Back to the future.. The future has come!
A way of showing the intent would be:
@Test
premiumDisplayedForAShortTermPolicy() {
given(theBroker.hasStartedAQuoteWithMinimumDataToConvertToNewBusiness());
and(theBroker.enters.field(DUE_DATE, oneMonthFromToday()));
when(theBroker.underwrites());
then(thePolicy.hasCurrentMotorPremiumDisplayed());
}
Or you could freeze time with Joda Time.
Is this a functional/acceptance (i.e. Selenium/WebDriver/etc.) test? If so I’d revisit the granularity of it.
It would probably be better to avoid mentioning form fields and other implementation details and focus on what matters as a functional spec -the goal and not the how.
Form-driven tests are often too coupled to the UI and therefore extremely brittle.
Cheers