BDD and JavaScript Using CucumberJS

| by Jan Stenberg Follow 34 Followers on Jan 31, 2014. Estimated reading time: 1 minute |

CucumberJS is a new tool that when added to the TDD workflow for JavaScript-based projects embraces the ideas of Behaviour Driven Development, BDD, allowing a developer to follow the TDD principles while developing from the outside in; running automated tests that fail until code that supports a feature is implemented, Todd Anderson reveals in a recent blog post.

Todd, an application developer and co-author of three books, describes CucumberJS as a port of the BDD tool Cucumber to JavaScript running both on NodeJS and modern web browsers. It allows definitions of feature specifications to be written in Gherkin and these specifications to be run using a command line tool which will report pass or fail of the steps and scenarios building up a specification. He notes though that Cucumber is only the testing framework, it's up to a developer to include an assertion library that will make these steps pass or fail.

Todd uses an earlier grocery list application as an example of how to adapt to BDD using Cucumber, giving one example of a feature:

Feature: Shopper can add an item to their Grocery List
Scenario: Item added to grocery list
Given I have an empty grocery list
When I add an item to the list
Then the grocery list contains a single item

The feature defines a business value, while the scenario defines the steps that provide that value. Each scenario has a list of steps defined by the keywords Given, When, Then; steps that CucumberJS will execute after having read the feature specification.
Using CucumberJS together with NodeJS, Todd walks through some examples of implementing and running the grocery list application while moving from all tests failing to all pass.

Todd concludes with a belief that there is a reward in having code under a test harness when it comes to refactoring and bug fixing, and with an ambition to follow up with new posts addressing how he uses CucumberJS to run tests integrating with a browser.

BDD was developed around 2006 by Dan North.
Cucumber is an open source tool for Behaviour Driven development, BDD, currently for nine programming languages, including JavaScript.

Rate this Article

Adoption Stage

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

One Quick Way to Create Your Cucumber.js Test Script by Jason Jing

You may want to know there is an editing tool to create Cucumber.js test script:

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

1 Discuss

Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you