Stuff about software development, agile and testing

Thursday, September 6, 2007

Fluent Interface

Like most other projects out there we are using fit/fitnesse to write our acceptance tests. But to be honest I am not very big fan of fitnesse. It doesn't scale very well with project size and having fixture tables through out fitnesse pages doesn't help readability and maintainability.

Especially if you are building web application you leave the UI part out of the test unless you integrate your UI test tool like selenium with fitnesse but you still miss the readability for tabular test structures. When we get story in BDD(Behaviour driven development) format and acceptance criteria in Given-Then-When style I expect to see my test in following pattern.

"Given products exists when I search product by name then user expect to see all matching products" do

test "goto product page and search for product code '100'
now number of matching products found is '10' "

end

Doing something like this Ruby is possible and in fact Dust is doing something very similar. But achieving something like this in Java is a challenge. Fluent Interface is one of the easiest way to do achieve DSL like look in Java and its quite easy to implement too. Lets consider the following selenium unit test

public void testGivenProductsExistsWhenISearchProductByNameThenUserExpectToSeeAllMatchingProducts() {

goToProductPage().andSearchForProductCode("100);
assertThat(now().numberOfMatchingProductsFoundIs("10"));
}


Its not cool as ruby DSL's but its close and quite readable. Some of our test now looks like this and rest of the team loves it.

Labels