April 10, 2008

BFD!

If Test-First Development (TFD) is a specialized subset of Test-Driven Development (TDD), then surely the equivalent specialized subset of Behavior-Driven Development is Behavior-First Development.

Today I had my first experience in developing BFD.

I know what you’re thinking:  BFD.

But it’s a BFD to me.  Using a rather exotic concoction of DBUnit, HSQLDB, Selenium, Cargo and EasyB, I was able to write a story  to describe some new functionality for a web application, and run that story as a test (via EasyB/Groovy), before I wrote any of the code to implement the functionality.

Other ingredients in this concoction:  Tomcat, Ant, Junit, Struts2, Spring, Cobertura and four or five different logging frameworks.

Observations:

  •  It is difficult to see what is going on when your story fails - the story failure is often fairly far away from the  code failure.
  • DBUnit throws multiple exceptions as part of normal operating procedure.  That is a crime against humanity.

Latest Cool Tool

I’m sure everyone else in the world found and mastered  XPath Checker long ago, but for those of you who haven’t, it is a fantastic Add-on for Firefox that lets you practice XPath expressions on real, live web pages.

Why would you want to do that? 

If you want to write Functional webapp tests via Selenium, a good, solid working knowledge of XPath is essentially mandatory for all but the most trivial of tests.

What about Selenium IDE? 

The Selenium IDE is incredibly helpful for navigating your pages, but it is not help at all with testing the content on those pages.

In other words, if you want to register a new user, add four things to your cart, visit your recommendations page and then check out, Selenium IDE will properly structure your clicks and everything else.

But if you want to find out if your checkout page lists your four items, and you need to be specific about where on the page  those items show up, you have to use XPath with Selenium to get to the correct table, div, what-have-you.

Enter XPath Checker.  During your Selenium IDE-driven  recording session, control-click on the page, and experiment with the correct XPath query to get to the cell/row/etc you want to see.