Home > Technical > Back to the future TDD

Back to the future TDD

December 20th, 2009

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());
}

Technical

  1. December 20th, 2009 at 19:32 | #1

    Or you could freeze time with Joda Time.

  2. December 28th, 2009 at 06:11 | #2

    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

  1. No trackbacks yet.