@Cukefy
I just had the privilege to participate in the Agile Testing class presented by Elisabeth Hendrickson and Dale Emery at the Agilistry studio in Pleasanton, CA. An important component of the class was a review of tools that support ATDD – we looked at Cucumber, Robot and Fitnesse. During the discussion on tools adoption, I brought up a point that many Java and C# shops eschew any external tools in favor of internal DSLs otherwise known as fluent style. Something like this:
//use Jane and Buick sample data for this test
PersonalPolicyBuilder policy =
PersonalPolicyBuilder.ownedBy(Jane_Smith() );
policy.addCar( BUICK_2000().withComprehensiveCoverage()
.withDeductibleOf( 500 )
.withMedicalLimit( 10000));
assertThat( policy.totalPremium(), equals( 765.00));
In the discussion that followed, many folks felt that there is still too much Java in this code snippet and that their ability to read this test is sufficiently impeded by it. Ok then…
How about we add a bit more syntactic sugar and an annotation to to trigger the translation from Java to something a bit more readable:
@Cukefy
public void testAddCarToPolicy() {
Given();
PersonalPolicyBuilder policy =
PersonalPolicyBuilder.ownedBy(Jane_Smith() );
When();
policy.addCar( BUICK_2000().withComprehensiveCoverage()
.withDeductibleOf$( 500 )
.withMedicalLimit$( 10000));
Then();
assertThat( policy.totalPremium(), equals$( 765.00));
}
and our translator will output something like:
Given:
Personal Policy owned by Jane Smith
When:
Add car Buick_2000 with Comprehensive Coverage
AND with Deductible of $500
AND with Medical Limit of $10,000
Then:
Total Premium should equal $765.00
Is that better? Would you use something like this? Let me know at david@vydra.net or tweet me @vydra
Till next time.
BTW, if your team is considering a transition to Agile Testing, there is not better way to get started than Elisabeth’s course.