BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

BDD and JavaScript Using CucumberJS

by Jan Stenberg on Jan 31, 2014 |

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.

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