Convert Figma logo to code with AI

cucumber logocucumber-jvm

Cucumber for the JVM

2,696
2,022
2,696
60

Top Related Projects

8,079

Test Automation Made Simple

Java DSL for easy testing of REST services

1,975

TestNG testing framework

6,314

✅ The 5th major version of the programmer-friendly testing framework for Java and the JVM

3,535

The Enterprise-ready testing and specification framework.

Quick Overview

Cucumber-JVM is the Java implementation of Cucumber, a popular behavior-driven development (BDD) tool. It allows developers to write executable specifications in plain language, bridging the gap between business stakeholders and development teams. Cucumber-JVM integrates seamlessly with Java projects, enabling automated testing and documentation of software behavior.

Pros

  • Promotes collaboration between technical and non-technical team members
  • Supports multiple programming languages and testing frameworks
  • Provides clear and readable test scenarios in Gherkin syntax
  • Facilitates test-driven development and continuous integration

Cons

  • Learning curve for writing effective Gherkin scenarios
  • Can lead to maintenance overhead if not properly managed
  • May require additional setup and configuration compared to traditional unit testing
  • Performance can be slower compared to pure unit tests for large test suites

Code Examples

  1. Basic Cucumber step definition:
@Given("I have {int} cucumbers in my basket")
public void i_have_cucumbers_in_my_basket(Integer count) {
    basket = new Basket(count);
}
  1. Using data tables in Cucumber scenarios:
@When("I add the following items to my basket:")
public void i_add_the_following_items_to_my_basket(DataTable dataTable) {
    List<Map<String, String>> items = dataTable.asMaps(String.class, String.class);
    for (Map<String, String> item : items) {
        basket.addItem(item.get("item"), Integer.parseInt(item.get("quantity")));
    }
}
  1. Asserting results in Cucumber steps:
@Then("the total price should be {double}")
public void the_total_price_should_be(Double expectedPrice) {
    assertEquals(expectedPrice, basket.getTotalPrice(), 0.01);
}

Getting Started

To get started with Cucumber-JVM, add the following dependencies to your Maven pom.xml file:

<dependencies>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>7.11.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>7.11.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Create a feature file in src/test/resources/features with your Gherkin scenarios, and implement the corresponding step definitions in your Java test classes. Run your Cucumber tests using JUnit or your preferred test runner.

Competitor Comparisons

8,079

Test Automation Made Simple

Pros of Karate

  • All-in-one testing framework with built-in API, UI, and performance testing capabilities
  • Simpler syntax and less boilerplate code compared to Cucumber-JVM
  • Native support for JSON and XML assertions

Cons of Karate

  • Less widespread adoption and community support than Cucumber-JVM
  • Limited integration with existing Java codebases and test frameworks
  • Steeper learning curve for developers familiar with traditional BDD frameworks

Code Comparison

Cucumber-JVM:

Feature: User Registration
  Scenario: Successful registration
    Given the user is on the registration page
    When they enter valid details
    And submit the form
    Then they should see a confirmation message

Karate:

Feature: User Registration
Scenario: Successful registration
  Given url 'https://example.com/register'
  And request { username: 'testuser', password: 'password123' }
  When method post
  Then status 200
  And match response contains { message: 'Registration successful' }

The Karate example demonstrates its focus on API testing with built-in HTTP request handling and response assertions, while Cucumber-JVM requires additional step definitions and custom code to achieve similar functionality.

Java DSL for easy testing of REST services

Pros of Rest-Assured

  • Specifically designed for API testing, offering a more focused and streamlined approach
  • Provides a fluent, easy-to-read DSL for writing API tests
  • Integrates well with existing Java test frameworks and tools

Cons of Rest-Assured

  • Limited to API testing, while Cucumber-JVM supports broader test scenarios
  • Less emphasis on behavior-driven development (BDD) compared to Cucumber-JVM
  • May require more setup for non-API related tests

Code Comparison

Rest-Assured example:

given()
    .param("key1", "value1")
    .header("Content-Type", "application/json")
.when()
    .get("/api/endpoint")
.then()
    .statusCode(200)
    .body("key", equalTo("value"));

Cucumber-JVM example:

Given the API endpoint "/api/endpoint"
And the request parameter "key1" is "value1"
And the request header "Content-Type" is "application/json"
When I send a GET request
Then the response status code should be 200
And the response body should contain "key" with value "value"

Both repositories offer valuable tools for testing, with Rest-Assured focusing on API testing and Cucumber-JVM providing a more versatile BDD approach. The choice between them depends on the specific testing needs and preferences of the development team.

1,975

TestNG testing framework

Pros of TestNG

  • More flexible test configuration and parallel execution capabilities
  • Built-in support for data-driven testing and parameterization
  • Comprehensive reporting and logging features

Cons of TestNG

  • Steeper learning curve for beginners compared to Cucumber's natural language approach
  • Less emphasis on behavior-driven development (BDD) and collaboration between technical and non-technical team members
  • May require more code to set up and maintain test suites

Code Comparison

TestNG:

@Test(groups = {"smoke"})
public void testLogin() {
    // Test implementation
}

Cucumber:

@Given("the user is on the login page")
public void userOnLoginPage() {
    // Step implementation
}

TestNG focuses on annotations and programmatic test configuration, while Cucumber emphasizes readable, natural language scenarios. TestNG provides more granular control over test execution, but Cucumber excels in creating easily understandable test specifications that can serve as living documentation for the application's behavior.

Both frameworks have their strengths and are widely used in the Java testing ecosystem. The choice between them often depends on the project's specific requirements, team preferences, and the desired balance between technical flexibility and non-technical stakeholder involvement in the testing process.

6,314

✅ The 5th major version of the programmer-friendly testing framework for Java and the JVM

Pros of JUnit 5

  • More extensive and flexible test lifecycle management
  • Better support for parallel test execution
  • Improved extensibility through custom extensions

Cons of JUnit 5

  • Steeper learning curve for developers new to JUnit
  • Less focus on behavior-driven development (BDD) style testing

Code Comparison

Cucumber-JVM (Feature file):

Feature: Login
  Scenario: Successful login
    Given I am on the login page
    When I enter valid credentials
    Then I should be logged in

JUnit 5:

@Test
void testSuccessfulLogin() {
    loginPage.open();
    loginPage.enterCredentials(validUsername, validPassword);
    assertTrue(loginPage.isLoggedIn());
}

Key Differences

  • Cucumber-JVM uses Gherkin syntax for writing human-readable test scenarios, while JUnit 5 uses standard Java code
  • JUnit 5 is more focused on unit testing, while Cucumber-JVM is designed for behavior-driven development and acceptance testing
  • Cucumber-JVM encourages collaboration between technical and non-technical team members, whereas JUnit 5 is primarily used by developers

Both tools have their strengths and are often used together in projects, with Cucumber-JVM for high-level acceptance tests and JUnit 5 for lower-level unit tests.

3,535

The Enterprise-ready testing and specification framework.

Pros of Spock

  • More expressive and readable test syntax with built-in BDD-style structure
  • Powerful mocking and stubbing capabilities integrated into the framework
  • Better support for data-driven testing with data tables and data pipes

Cons of Spock

  • Limited to Groovy language, while Cucumber-JVM supports multiple JVM languages
  • Steeper learning curve for developers not familiar with Groovy
  • Less suitable for non-technical stakeholders compared to Cucumber's Gherkin syntax

Code Comparison

Spock example:

def "adding two numbers"() {
    expect:
    Math.max(a, b) == c

    where:
    a | b | c
    1 | 3 | 3
    7 | 4 | 7
    0 | 0 | 0
}

Cucumber-JVM example:

Scenario Outline: Adding two numbers
  Given I have the numbers <a> and <b>
  When I calculate their maximum
  Then the result should be <c>

  Examples:
    | a | b | c |
    | 1 | 3 | 3 |
    | 7 | 4 | 7 |
    | 0 | 0 | 0 |

Both frameworks offer powerful testing capabilities, but Spock provides a more concise and expressive syntax for developers, while Cucumber-JVM excels in readability for non-technical stakeholders and supports multiple JVM languages.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Cucumber JVM

#StandWithUkraine OpenCollective OpenCollective Maven Central Build Status Coverage Status

Cucumber-JVM is a pure Java implementation of Cucumber. You can run it with the tool of your choice.

Cucumber-JVM also integrates with all the popular Dependency Injection containers.

Getting started

Upgrading?

Migration instructions from previous major versions and a long form explanation of noteworthy changes can be found in the release-notes archive

The changes for the current major version can be found in the CHANGELOG.md.

Questions, Problems, Help needed?

Please ask on

Bugs and Feature requests

You can register bugs and feature requests in the GitHub Issue Tracker.

Please bear in mind that this project is almost entirely developed by volunteers. If you do not provide the implementation yourself (or pay someone to do it for you), the bug might never get fixed. If it is a serious bug, other people than you might care enough to provide a fix.

Contributing

If you'd like to contribute to the documentation, checkout cucumber/docs.cucumber.io otherwise see our CONTRIBUTING.md.