CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-cucumber--cucumber-java

Cucumber-JVM Java library providing annotation-based step definitions for Behavior-Driven Development (BDD) testing

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

Cucumber-Java

Cucumber-Java provides annotation-based step definitions for Behavior-Driven Development (BDD) testing within the Cucumber framework. It enables developers to write automated tests in plain language that can be read by both technical and non-technical team members, improving communication and collaboration in software development teams.

Package Information

  • Package Name: cucumber-java
  • Package Type: Maven
  • Group ID: io.cucumber
  • Artifact ID: cucumber-java
  • Language: Java
  • Installation: Add dependency to pom.xml:
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>7.22.1</version>
    <scope>test</scope>
</dependency>

Core Imports

import io.cucumber.java.en.*;
import io.cucumber.java.Before;
import io.cucumber.java.After;
import io.cucumber.java.Scenario;
import io.cucumber.java.PendingException;
import io.cucumber.java.ParameterType;
import io.cucumber.java.DataTableType;
import io.cucumber.java.DocStringType;

For other languages (internationalization):

import io.cucumber.java.fr.*;  // French
import io.cucumber.java.de.*;  // German
import io.cucumber.java.es.*;  // Spanish
// 70+ other language packages available

Basic Usage

package com.example.stepdefs;

import io.cucumber.java.en.*;
import io.cucumber.java.Before;
import io.cucumber.java.After;
import io.cucumber.java.Scenario;

public class CalculatorStepDefinitions {
    private Calculator calc;

    @Before
    public void setUp() {
        calc = new Calculator();
    }

    @Given("a calculator I just turned on")
    public void a_calculator_I_just_turned_on() {
        // Calculator already initialized in setUp
    }

    @When("I add {int} and {int}")
    public void adding(int arg1, int arg2) {
        calc.push(arg1);
        calc.push(arg2);
        calc.push("+");
    }

    @Then("the result is {int}")
    public void the_result_is(int expected) {
        assertEquals(expected, calc.value());
    }

    @After
    public void tearDown(Scenario scenario) {
        if (scenario.isFailed()) {
            scenario.log("Test failed: " + scenario.getName());
        }
    }
}

Architecture

Cucumber-Java is built around several key architectural components:

  • Step Definition Annotations: Language-specific annotations (@Given, @When, @Then) generated for 70+ languages
  • Hook System: Lifecycle management with @Before, @After, @BeforeAll, @AfterAll, @BeforeStep, @AfterStep
  • Parameter Transformation: Custom parameter types with @ParameterType and default transformers
  • Data Handling: Built-in support for data tables and doc strings with custom transformations
  • Runtime Context: Scenario object provides access to test execution context and reporting
  • Internationalization: Code generation system creates localized step definition annotations

Capabilities

Step Definitions

Core step definition annotations for writing BDD test steps in multiple languages. Supports both Cucumber expressions and regular expressions.

// English annotations (most commonly used)
@Given("step text with {parameter}")
@When("step text with {parameter}")
@Then("step text with {parameter}")
@And("step text with {parameter}")
@But("step text with {parameter}")

Step Definitions

Lifecycle Hooks

Comprehensive hook system for test setup, teardown, and step-level interception across different scopes.

@Before("@tag-expression")
public void setUp(Scenario scenario) { }

@After(order = 1000)
public void tearDown(Scenario scenario) { }

@BeforeAll  // EXPERIMENTAL
public static void beforeAll() { }

@AfterAll   // EXPERIMENTAL
public static void afterAll() { }

Lifecycle Hooks

Parameter Transformation

Custom parameter types for converting step parameters from strings to domain objects, with extensive configuration options.

@ParameterType("\\d{4}-\\d{2}-\\d{2}")
public LocalDate date(String dateString) {
    return LocalDate.parse(dateString);
}

@DefaultParameterTransformer
public Object defaultTransformer(String fromValue, Type toValueType) {
    // Custom transformation logic
    return transformed;
}

Parameter Transformation

Data Handling

Robust data table and doc string handling with custom transformations and built-in collection support.

@DataTableType
public Person personEntry(Map<String, String> entry) {
    return new Person(entry.get("name"), entry.get("email"));
}

@DocStringType
public JsonNode json(String docString) {
    return objectMapper.readTree(docString);
}

Data Handling

Runtime Context

Access to scenario information, status, and reporting capabilities during test execution.

public class Scenario {
    Collection<String> getSourceTagNames();
    Status getStatus();
    boolean isFailed();
    void attach(byte[] data, String mediaType, String name);
    void attach(String data, String mediaType, String name);
    void log(String text);
    String getName();
    String getId();
    URI getUri();
    Integer getLine();
}

public enum Status {
    PASSED, SKIPPED, PENDING, UNDEFINED, AMBIGUOUS, FAILED, UNUSED
}

Runtime Context

Types

// Core exception for marking unimplemented steps
public final class PendingException extends RuntimeException {
    public PendingException();
    public PendingException(String message);
}

// Annotation for transposing data tables (used on parameters)
public void stepWithTransposedTable(@Transpose DataTable table) { }

// Meta-annotations for step definitions (internal use)
@StepDefinitionAnnotation
@StepDefinitionAnnotations

docs

data-handling.md

hooks.md

index.md

parameter-transformation.md

runtime-context.md

step-definitions.md

tile.json