Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Open Source

Behavior-Driven Development With easyb

Behavior-driven development (BDD) is an iterative, incremental, agile methodology for software development. BDD methodology brings all the stakeholders (business analysts, users, project managers, and developers) together and therefore minimizes the translation between the technical language in which code is written and the domain language used in describing requirements. In BDD, all stakeholders get together to create stories, which describe different requirements using examples (referred to as "scenarios" in BDD). These scenarios are then automated to give quick feedback or regression.

BDD is an outside-in approach, which usually involves creating stories before the actual development starts. The test cases are run iteratively throughout the entire development cycle until all test cases pass. This ensures that there are no regressions and helps development teams deliver clean code that covers all requirements.

easyb, which won a Jolt Award in 2009, is an open-source BDD framework for the Java platform. Its specifications are written in Groovy and executed via a Java runner that can be invoked from the command line, Maven 2, or Ant. easyb has an out-of-the-box reporting tool that provides test results in HTML and XML formats. And easyb supports story-based DSLs with given, when, and then keywords.

easyb is distributed under the MIT license and is hosted at Google code, which provides an accessible Subversion repository. Building easyb requires Groovy 1.6.0 and Gant 1.6.0.

This article provides an overview of various keywords used in easyb to write a story file, the easyb software development lifecycle, using easyb as a test driver, and the different ways in which easyb artifacts can be organized in a project.


Stories are sequences of events, narratives, or statements between developers and business stakeholders. A story provides a description of a requirement or use case that can be validated. Stories are created using predefined keywords so that a use case can be described completely.

Narratives are written in the beginning of a story file. Narratives give an overview of a story:

narrative "regarding stock  availability", {
	as_a "customer who places order on online retail portal"
	i_want "to be able to see a confirmation message about availability of stock"
	so_that "I know whether my order can be completed successfully or not."

Scenarios help describe easyb stories. Every scenario has a precondition described by given, a test execution described by when, and validations described by then:

scenario "A customer orders a music player which is in stock",{
	given "There is music player in stock",{}
	when "A customer orders a music player",{}
	then "The order should be placed successfully and a success message should be displayed to customer.",{}
scenario "A customer orders 5 AA batteries out which only 3 AA batteries are in stock",{
	given "There are 3  AA batteries in stock",{}
	when "A customer orders 5 AA batteries",{}
	then "The order should not be placed and a failure message should be displayed to customer",{}

Fixtures are a precondition that needs to be set for all scenarios using before. A precondition that needs to be executed before every scenario is set using before_each. Usually, these keywords are used to perform activities, such as initializing variables, bouncing servers, etc., which must be performed before scenarios start running.

before "bounce tomcat server", {
	given "server is up and running", {

If there is a requirement that the server should be bounced before every scenario, then the before_each keyword should be used.

Shared behaviors, as the name suggests, are basic scenarios that are constructed if there is a certain functionality that is shared across many scenarios in the story file. This scenario is later referred to in other scenarios.

shared_behavior "login", {
	given "a valid user", {

	when "the user logins with valid credentials ", { Application.login() }

scenario "user can see a welcome page when the login is successfull", {
	it_behaves_as "login"

	then "the welcome page is displayed", {
		//code to inspect elements of welcome page

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.