InfoQ

News

Story Driven Development Recipes with Cucumber

Posted by Sebastien Auvray on Mar 03, 2009

Community
Ruby,
Agile,
Java
Topics
Software Testing ,
Agile Techniques ,
Collaboration
Tags
RSpec

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.

Related Sponsor

VersionOne is recognized by Agile practitioners as the leader in Agile project management tools. Companies such as Adobe, BBC, CNN, Dow, HP, IBM, Sony and 3M have turned to VersionOne to help deliver greater value to their customers.

No comments

Watch Thread Reply

Educational Content

Brian Marick on 4 Challenges and 5 Guiding Values of Agile Software Development

Brian Marick takes us through a quick tour of the most important values and challenges to adopting Agile successfully (they aren't the typical challenges and values we hear in the community).

Are You a Software Architect?

The line between development and architecture is tricky. Does it exist at all? Is an ivory tower actually needed? There's a balance in the middle, but how do you move from developer to architect?

Agile – A Way of Life and Pragmatic Use of Authority

The word 'authority' sometimes produces an allergic response in hard-line agilists. Freedom and authority – both are bad if misused and both are good if used in right spirit for a noble cause.

Getting Started with Grails, Second Edition

"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, and Taco Bell are all using Grails. Are you ready to get started as well?

Using ITIL V3 as a Foundation for SOA Governance

Those familiar with only ITIL V2 often scoff at the thought that ITIL could serve as a governance framework for SOA. With ITIL V3, the focus of the framework shifted towards service-orientation.

Adrian Colyer on AspectJ, tc Server and dm Server

SpringSource CTO Adrian Colyer discusses AspectJ, SpringSource's dm Server and tc Server products, OSGi and Scrum.

Adam Wiggins on Heroku

Heroku's Adam Wiggins talks about Rails, Background Jobs, Add-Ons, Ruby, and how Heroku manages to work around Ruby's inefficiencies using Erlang and other languages.

SOA as an Architectural Pattern: Best Practices in Software Architecture

For Grady Booch the foundation of a good architecture is patterns, SOA being just one of many patterns. In this Second Life presentation, Booch attempts to bring more clarity on what architecture is.