small medium large xlarge

The Cucumber for Java Book: Behaviour-Driven Development for Testers and Developers


Cover image for The Cucumber for Java Book

The Cucumber for Java Book

Behaviour-Driven Development for Testers and Developers


Teams working on the JVM can now say goodbye forever to misunderstood requirements, tedious manual acceptance tests, and out-of-date documentation. Cucumber—the popular, open-source tool that helps teams communicate more effectively with their customers—now has a Java version, and our bestselling Cucumber Book has been updated to match. The Cucumber for Java Book has the same great advice about how to deliver rock-solid applications collaboratively, but with all code completely rewritten in Java. New chapters cover features unique to the Java version of Cucumber, and reflect insights from the Cucumber team since the original book was published.

Printed in full color.


Customer Reviews

This book is not just for programmers but for testers as well. It goes beyond using
Cucumber; it gives testing guidelines as well and hints and tips to avoid bad tests.

- Janet Gregory

Author, "Agile Testing: A Practical Guide for Testers" (with Lisa Crispin)

If you read this book in the morning, then find a stakeholder quickly enough,
you’ll be writing effective scenarios with that person in the afternoon. Start today.

- J.B. Rainsberger

Author, "JUnit Recipes"

The best thing about this book: it will help you identify WHY you may want to use
Cucumber, and it will guide you to good ways to do it in collaboration with your
whole team.

- Lisa Crispin

Author, "Agile Testing: A Practical Guide for Testers" (with Janet Gregory)

This is an excellent introduction to using Cucumber on the JVM that guides the
reader clearly through the complexities of the API and away from common pitfalls
in its application to real projects.

- Nat Pryce

Author, "Growing OO Software Guided By Tests" (with Steve Freeman)

[If you] implement an application in a test-first manner, taking small and careful
steps and alternating implementation and refactoring phases, your tests will tell
you what to do next. So listen to your tests and listen to this book!

- Gáspár Nagy

Creator of SpecFlow - Cucumber for .NET

This book will teach you all you need to know to get started with Cucumber on
the Java platform…although the authors make sure that nonprogrammers can
follow along. It will find its place on my bookshelf and in the book recommendations
I give out in my training classes.

- Markus Gaertner

Author, _ATDD by Example_

This is a great reference guide for software project builds maintainers, because
the authors carefully address the integration of Cucumber with other Java platform
favorites such as JDBC, databases, dependency injection containers such as CDI
and Spring Framework, and REST server-side endpoints.

- Peter Pilgrim

Author, "The Java EE 7 Developer Handbook"

The Cucumber for Java Book meets an important need—the large Java community
has a great tool in Cucumber but very limited documentation on how to use it
effectively. This is the book I’ll recommend to my Java clients who want to hit the
ground running with Cucumber.

- Richard Lawrence

BDD Trainer and Coach, Agile for All

A gentle yet complete introduction to Cucumber on the JVM. An excellent stepby-
step guide with attention to detail.

- Paul Grenyer

Founder, Naked Element and NorDevCon

The material [in this book] is built on real-life experiences with appreciation for
the everyday problems we as testers/software architects/managers face both internally
and externally.

- Márton Mészáros

Founder, Tailored Tunes and Test Automation Specialist

The authors get the combination of technical and nontechnical lessons across
very well. A very good read for the novice and experienced BDD follower alike.

- Craig Harrison

Software Engineer

See All Reviews

Choose Your Format(s)

  • $24.00 In Stock
  • Ebooks are DRM free.

  • Ebook delivery options.

About this Title

Pages: 338
Published: 2015-02-15
Release: P1.0 (2015-02-11)
ISBN: 978-1-94122-229-4

Until now it’s been difficult for teams developing Java applications to learn how to benefit from Behaviour-Driven Development (BDD). This book changes all that by describing in detail how to use Cucumber to harness the power of plain language specifications in your development process.

In part 1, you’ll discover how to use Cucumber’s Gherkin DSL to describe the behavior your customers want from the system. You’ll also learn how to write Java code that interprets those plain language specifications and checks them against your application. Part 2 guides you through a worked example, using Spring, MySQL, and Jetty. Enhanced chapters teach you how to use Selenium to drive your application and handle asynchronous Ajax calls, and new chapters cover Dependency Injection (DI) and advanced techniques to help keep your test suites fast. Part 3 shows you how to integrate Cucumber with your Continuous Integration (CI) system, work with a REST web service, and even use BDD with legacy applications.

Written by the creator of Cucumber and two of its most experienced users and contributors, The Cucumber for Java Book is an authoritative guide that will give you and your team all the knowledge you need to start using Cucumber with confidence.


The Cucumber for Java Book – Q&A

What is Cucumber?

Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests, and collaborative development-aid—all rolled into one format.

Who is this book for?

The first part of this book is for the whole team—customer, product owner, business analyst, developer, tester, architect, Scrum master, and anyone else you can think of. The rest of the book focuses on more technical aspects of Cucumber for Java and is suitable mainly for developers and testers.

How will this book help us at work?

Seb, Matt, and Aslak have spent years consulting in a wide variety of organizations. In response, we developed Cucumber to help support the effective ways of working that we had learned. In this book you get the distillation of all that knowledge, along with in-depth advice that will help you be successful at Behaviour-Driven Development (BDD) using Cucumber.

Can’t I learn all this from the online documentation?

The online documentation gives you the bare bones of how Cucumber for Java works. This book has much more. From the invaluable BDD advice in part 1, through the extensive worked example in part 2, to the detailed technical insights in part 3, this book collects everything you need to know in one handy package.

Is the book useful even if my project isn’t written in Java?

Cucumber doesn’t care what language your project is written in. As long as there’s a way to interface with your project from Java, then Cucumber for Java can work for you. If your project is written in Java (or another JVM language), then your Cucumber scenarios can interact directly with the code, which can be very useful. The book also gives a brief introduction to writing your “glue” code in other JVM languages, such as Scala, Groovy, or Clojure.

Is this the same as The Cucumber Book?

The Cucumber for Java Book is based upon the best-selling original, The Cucumber Book. All the examples have been completely rewritten to take advantage of the Java version of Cucumber. There are new chapters that cover Java specific topics, such as Cucumber’s integration with various dependency injection containers, and there’s a brand new chapter on how to keep your Cucumber scenarios running fast as your project grows.

Is Cucumber just another test automation tool?

No it isn’t. Cucumber is a collaboration and documentation tool first. Start by getting your business people to collaborate effectively with your technical teams. Then use Cucumber to document those interactions as described in the book. Finally, automate those interactions using Cucumber to get the full value from your improved development process. Teams that try to use Cucumber only as a test automation tool generally find that it is the wrong tool—because that’s not what it was designed for.

What You Need

You’ll need any system with an installed JVM 1.6 or later and Maven. The examples in the book work with versions of Cucumber-JVM from 1.1.3 upwards.

Contents & Extracts

  • Cucumber-JVM Fundamentals
    • Why Cucumber-JVM?
      • Automated Acceptance Tests
      • Behaviour-Driven Development
      • Living Documentation
      • How Cucumber-JVM Works
      • What We Just Learned
    • First Taste
      • Understanding Our Goal
      • Creating a Feature
      • Creating Step Definitions
      • Implementing Our First Step Definition
      • Changing Formatters
      • Testing Our Checkout Class
      • Adding an Assertion
      • Making It Pass
      • What We Just Learned
    • Gherkin Basics
      • What’s Gherkin For?
      • Format and Syntax
      • Feature
      • Scenario
      • Comments
      • Spoken Languages
      • What We Just Learned
    • Step Definitions: From the Outside
      • Steps and Step Definitions
      • Capturing Arguments
      • Multiple Captures
      • Flexibility
      • Returning Results
      • What We Just Learned
    • Expressive Scenarios
      • Background
      • Data Tables
      • Scenario Outline
      • Too Much Information
      • Doc Strings
      • Staying Organized with Tags and Subfolders
      • What We Just Learned
    • When Cucumbers Go Bad
      • Feeling the Pain
      • Working Together
      • Caring for Your Tests
      • Stop the Line and Defect Prevention
      • What We Just Learned
  • A Worked Example
    • Step Definitions: On the Inside
      • Sketching Out the Domain Model excerpt
      • Staying Honest with Transforms
      • Adding Custom Helper Methods
      • Organizing the Code
      • Dependency Injection
      • What We Just Learned
    • Support Code
      • Fixing the Bug
      • Bootstrapping the User Interface
      • Making the Switch
      • Using Hooks
      • Getting to green
      • What We Just Learned
    • Dealing with Message Queues and Asynchronous Components
      • Our New Asynchronous Architecture
      • How to Synchronize
      • Implementing the New Architecture
      • Fixing the Flickering Scenario
      • What We Just Learned
    • Databases
      • Iterative Database Development
      • Refactoring to Use a Database
      • Reading and Writing to the Database
      • Cleaning the Database with Transactions
      • Cleaning the Database with Truncation
      • What We Just Learned
    • Simplifying Our Design Using Dependency Injection excerpt
      • DI and Cucumber-JVM
      • Improving Our Design Using DI
      • PicoContainer is Almost Invisible
      • Moving to Guice
      • Spring in Your Steps
      • CDI with Weld
      • What We Just Learned
    • Working With Web Applications
      • Selenium WebDriver
      • Handling Failure excerpt
      • Reusing the Browser
      • AJAX
      • What We Just Learned
    • Keeping Your Features Fast
  • More Techniques
    • Controlling Cucumber-JVM
    • Working with a REST web service
    • Working with Legacy Applications


Seb Rose* works as an independent consultant, helping teams adopt and refine their agile practice. He works with Kickstart Academy and is a core developer on the Cucumber-JVM project. Seb tweets as @sebrose and blogs at claysnow

Matt Wynne is a leading BDD practitioner, a member of the Cucumber core team, and a programmer, coach, trainer, and popular international speaker. Alongside Aslak Hellesøy and Julien Biezemans, Matt is co-founder of Cucumber Ltd., the company behind Cucumber. Matt tweets from @mattwynne and @cucumberbdd.

Aslak Hellesøy is the creator of Cucumber. During his career Aslak has worked with both small and large organizations in industries such as telecom, trading, insurance, car manufacturing, education, and government. Aslak is co-founder of Cucumber Ltd, the company behind Cucumber. He tweets from @aslak_hellesoy and @cucumberbdd.