Hello World
The smallest possible SpecBinder example. A single scenario with plain steps — no parameters, no rules, no configuration.
Source: examples/getting-started/example-1 on GitHub.
What this demonstrates
- Minimal setup: one marker class plus one
.featurefile - How
@Gherkin2JUnit("path")triggers code generation Given/When/Thensteps become method calls in the generated test class- The marker class is empty — step implementations come later
The feature file
src/test/resources/specs/ShoppingCart.feature
Feature: ShoppingCart
Scenario: A first scenario
Given I have an empty shopping cart
When I add an item
Then the cart should contain one item
The marker class
ShoppingCartFeature.java
package com.example.shop;
import dev.specbinder.annotations.Gherkin2JUnit;
@Gherkin2JUnit("specs/ShoppingCart.feature")
public abstract class ShoppingCartFeature {
}
The generated test class
After compilation, the processor writes ShoppingCartScenarios.java to target/generated-test-sources/:
target/generated-test-sources/.../ShoppingCartScenarios.java
public abstract class ShoppingCartScenarios extends ShoppingCartFeature {
public abstract void iHaveAnEmptyShoppingCart();
public abstract void iAddAnItem();
public abstract void theCartShouldContainOneItem();
@Test
@DisplayName("Scenario: A first scenario")
public void scenario_1() {
/* Given I have an empty shopping cart */
iHaveAnEmptyShoppingCart();
/* When I add an item */
iAddAnItem();
/* Then the cart should contain one item */
theCartShouldContainOneItem();
}
}
By default, the generated class is abstract with one abstract method per step. You implement the steps by creating a concrete subclass — see Implementing Steps for the next step.
Run it
cd examples/getting-started/example-1
mvn test