Skip to content
Tutorials Center
My learning

Topics

Cucumber and BDD Tutorial

Learn Cucumber and BDD step by step: 37 lessons in 9 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is Cucumber? Learn what Cucumber is, what problem it solves, how plain-language Gherkin specifications become automated tests, and when it is (and is not) the right tool.
  2. 2 How Cucumber Works: Features, Glue and Runner Understand the moving parts of Cucumber: feature files, step definitions called glue, the runner, and the life of a scenario from parsing to pass, fail, undefined or skipped.
  3. 3 Setting Up a Cucumber Project (Maven and Gradle) Set up a Cucumber-JVM project with Maven or Gradle and JUnit 5: dependencies, folder layout, the runner suite, configuration properties and a first command to run it.
  4. 4 Your First Feature, End to End Write a first Cucumber feature, see the undefined-step snippets, implement the steps against a small domain class, and watch the scenario go from red to green.

BDD Concepts and Gherkin

  1. 5 BDD Basics: Behavior Before Code Learn what Behavior-Driven Development is, how it differs from TDD and ATDD, the discover-formulate-automate cycle, and why examples beat requirements documents.
  2. 6 The Three Amigos and Example Mapping Run effective discovery sessions: who the three amigos are, how example mapping uses rules, examples and questions, and how to turn the outcome into Gherkin scenarios.
  3. 7 Gherkin Syntax: Feature, Scenario, Given, When, Then A complete tour of Gherkin: Feature, Scenario, Given When Then, And and But, comments, descriptions, tags, indentation and languages, with a runnable parser stand-in.
  4. 8 Background, Rules and Organizing Scenarios Use Background to share setup steps, Rule to group scenarios by business rule, and good file organization to keep feature files short, focused and easy to navigate.
  5. 9 Declarative Scenarios: Say What, Not How Learn the difference between imperative and declarative Gherkin, why UI details make scenarios brittle, and how to rewrite them in the language of the business.

Step Definitions

  1. 10 Step Definition Basics Write Cucumber-JVM step definitions: the Given, When and Then annotations, method signatures, assertions, pending steps, ambiguity errors, class organization and Kotlin.
  2. 11 Cucumber Expressions: {int}, {string}, Optionals and Alternatives Master Cucumber expressions: built-in parameter types such as int, float, word and string, optional text, alternation, escaping, and how they compile to regular expressions.
  3. 12 Regular Expression Step Patterns Use regular expressions in Cucumber step definitions: how Cucumber decides between regex and Cucumber expressions, capture groups, anchors, greedy pitfalls and optional groups.
  4. 13 Custom Parameter Types Define custom Cucumber parameter types with @ParameterType to turn sentence fragments into enums, dates and domain objects, keeping step definitions free of parsing code.
  5. 14 Sharing State Between Steps and Step Classes Share state between Cucumber steps safely: instance fields, a scenario-scoped world object, PicoContainer and Spring injection, and why static fields cause flaky tests.

Scenario Outlines and Data

  1. 15 Scenario Outlines and Examples Tables Run one scenario template against many data rows with Scenario Outline and Examples: placeholder syntax, how outlines expand, naming rows, reporting and when not to use them.
  2. 16 Data Tables in Steps Pass structured data to a Cucumber step with data tables: the DataTable API, lists of maps, key-value tables, custom @DataTableType conversion to objects and table diffs.
  3. 17 Doc Strings: Multi-Line Text in Steps Pass multi-line text such as emails, JSON and logs to a Cucumber step with doc strings: triple-quote syntax, indentation rules, content types and @DocStringType conversion.
  4. 18 Examples Tables in Depth: Choosing the Right Data Design the data behind Scenario Outlines: multiple named Examples blocks, equivalence classes, boundary values, avoiding combinatorial explosions and keeping tables readable.

Hooks and Tags

  1. 19 Hooks: Before, After and Friends Learn Cucumber hooks: Before and After, BeforeStep and AfterStep, BeforeAll and AfterAll, execution order, failures in hooks and what the Scenario object offers.
  2. 20 Tags and Tag Expressions Use Cucumber tags to group, filter and skip scenarios: placement and inheritance, tag expressions with and, or, not, tagged hooks and how to run tags from the command line.
  3. 21 Sharing State: World and Dependency Injection Share state between Cucumber step definition classes safely: one object per scenario, the World in Cucumber.js, PicoContainer and Spring injection, and why static fields break tests.
  4. 22 Test Data Setup and Cleanup Manage test data in Cucumber suites: Given steps versus hooks, data builders, unique values, rollback and cleanup strategies, and keeping scenarios independent.

Page Objects and UI Tests

  1. 23 The Page Object Pattern Learn the page object pattern: keep locators and browser calls out of Cucumber steps, design intention-revealing methods, return page objects, and test them with a fake driver.
  2. 24 Selenium with Cucumber: Setup and Driver Lifecycle Wire Cucumber to Selenium: Maven dependencies, the JUnit Platform runner, a driver factory, per-scenario browser start and quit, headless options and failure screenshots.
  3. 25 Component Objects, Waits and Stable Locators Split big page objects into component objects, choose stable locators, and use explicit waits instead of sleeps so Cucumber UI scenarios stop being flaky.
  4. 26 API and Service-Layer Scenarios Test business rules below the UI with Cucumber: service-layer scenarios, REST API steps with an HTTP client, sharing the last response, and choosing the right level of test.

Reporting and CI

  1. 27 Reports and Plugins Produce readable Cucumber reports: the pretty, summary, html, json, junit and message plugins, publishing, rerun files, Allure and attachments, plus a runnable reporter stand-in.
  2. 28 Running Scenarios in Parallel Run Cucumber scenarios in parallel: JUnit Platform settings, thread-safe state, ThreadLocal drivers, shared data and resource locks, Cucumber.js and Ruby options.
  3. 29 Cucumber in CI Pipelines: Maven, Gradle, GitHub Actions Run Cucumber in continuous integration: Maven and Gradle setup, GitHub Actions and GitLab examples, tag-based stages, headless browsers, archived reports and exit codes.

Patterns and Pitfalls

  1. 30 Declarative vs Imperative Scenarios Learn the difference between imperative, click-by-click Gherkin and declarative scenarios that state behavior, with rewriting recipes, a checklist and a runnable scenario linter.
  2. 31 Cucumber Anti-Patterns and How to Fix Them Spot and fix common Cucumber anti-patterns: UI scripts, giant scenarios, feature-coupled steps, hidden setup, assertion overload, test-case lists and duplicate steps.
  3. 32 Flaky and Slow Suites: Diagnosis and Cures Find and fix flaky Cucumber scenarios and speed up slow suites: causes, a diagnosis routine, quarantine tags, honest retries, shortcuts for login and setup, and test levels.
  4. 33 Three Amigos, Example Mapping and Living Documentation Learn the collaboration side of BDD: the three amigos, example mapping, the discover-formulate-automate cycle, and how Cucumber feature files become living documentation.

Projects and Practice

  1. 34 Project: Bank Account Behavior Build a bank account feature test-first: discover rules, write Gherkin with scenario outlines, run it in a Java mini runner, then see the matching real Cucumber-JVM glue.
  2. 35 Project: Shopping Cart with Background and Outlines A second BDD project: model a shopping cart with coupons and shipping rules, using Background, Scenario Outline tables and tags, run in a Java mini runner.
  3. 36 Project: Build a Mini Gherkin Runner Understand Cucumber by building a tiny version: parse Gherkin into scenarios, expand outlines, turn Cucumber expressions into regex, run hooks and tags, and print a report.
  4. 37 Practice: Hooks, Tags, UI Tests and Suite Health Practice what you learned about Cucumber hooks, tags, page objects, reports, CI and scenario quality: ten exercises with solutions, runnable checks and a review cheat sheet.