Getting to know Cukes
2009-11-06 16:48
Is Behavior-Driven Development just syntactic sugar for integration testing?
That's the question I have been asking more than once recently. There's RSpec,
and there's Cucumber - if you are a Ruby developer you'd have heard about
those. But why should you do BDD? Because BDD tests cover something Unit Tests
don't? That's not the case - in terms of code coverage, BDD doesn't add
anything.
(Take a Rails application for example. You can test model
integrity with unit tests; application logic with functional tests; and
user-app interaction flow with integration tests. That's complete coverage).
Having these doubts about BDD I was eager to sit in on the Cucumber
session with Aslak Hellesöy. Things were a bit more involved than I
thought. Firstly, it became obvious that Cucumber (or Gharkin, the DSL that
powers it) parses human-readable text into strings into which regular
expressions can be inserted at runtime.
(Ample amounts of
human-readable text is what flashes in the eye when first viewing BDD code.
It's easy to think of BDD as something only non-techies can read, but there's
more to the picture).
Another interesting detail is that Cucumber
follows a well-defined convention for testing. You are Given something, and
When you do something else Then something third happens. That's a nice coupling
of syntax and semantics. Function follows form. Otherwise it'd be easy to get
an impression that nearly everything goes into a Cucumber test spec.
Upon asking Aslak what exactly is Cucumber for: is it mainly for stakeholder
- developer communication or is it a superior testing tool aimed at the
developer, I received the following answer:
"Cucumber is a
stakeholder-team communication tool designed to add more value to the client,
however it is also a good developer tool that is capable of providing project
documentation at all stages of development: before-coding, during-coding, and
after-coding".
A good and exhaustive answer. Now, is Cucumber for
you?




