BT

Story Driven Development Recipes with Cucumber

by Sebastien Auvray on Mar 03, 2009 |

Behavior Driven Development's (BDD) popularity cannot be denied. It is a response to Test Driven Development (TDD) and was introduced by Dan North in 2003. BDD encourages collaboration between the various parties involved in a software project: developers, QA and non-technical or business analyst.

Easy creation and use of DSLs in Ruby allowed the birth of many BDD frameworks, such as RSpec. Cucumber, written by Aslak Hellesøy is another example, which can also be used to test Java, .NET and Flex code. It can execute plain-text documents as automated functional tests.

Here is a typical scenario example (from the project Wiki):

Feature: Search courses
  In order to ensure better utilization of courses
  Potential students should be able to search for courses

  Scenario: Search by topic
    Given there are 240 courses where neither has the topic "biology" 
    And there are 3 courses A,B,C that each have "biology" as one of the topics
    When I search for "biology" 
    Then I should see a the following courses:
      | title |
      | A     |
      | B     |
      | C     |

Then you can implement the actual code this recipe describes, and iterate with test failure until success. Cucumber supports highlighting of failing or successful parts of the scenario (Image from the Cucumber website):

Tests failure

The format used to write Cucumber recipes is the Gherkin language, which can be skinned for different natural languages, ie. the keywords like "Given", "And", etc. can also be written in languages like French, German, etc. The natural language text to the right of the keywords is interpreted by a programmatic step definition, ie. it executes code to perform the step.

There are many different ways to use Cucumber such as Web app integration testing for sysadmins or to Integrate Distributed Systems and Test Messaging or PDF Writing tests.

Cucumber 0.1.16 version is available as a Ruby Gem and 0.1.99.10 is available at GitHub.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT