Skip to main content

Examples

The fastest way to learn SpecBinder is to read a small, focused example for the construct you care about. Every example below ships as a runnable Maven project in the SpecBinder repository — clone it and mvn test to see the generated code on your own machine.

Basics

The fundamentals — one Gherkin construct per example.

ExampleWhat it covers
Hello WorldThe smallest possible feature — one scenario, plain steps, no parameters
Step ParametersType inference for quoted values: String, Integer, Long, Double, Boolean, Character
Implementing StepsEnd-to-end working example with real assertions and shared state
RulesGherkin Rule blocks → JUnit @Nested test classes
BackgroundFeature- and rule-level Background blocks → @BeforeEach
Scenario OutlineParameterized scenarios → JUnit @ParameterizedTest with @CsvSource
TagsGherkin tags → JUnit @Tag for selective execution

Common use cases

Patterns that come up beyond the basics.

ExampleWhat it covers
Typed Data TablesThe default LIST_OF_OBJECT_PARAMS mode — typed inner classes
Cucumber Data TablesThe CUCUMBER_DATA_TABLE mode for Cucumber's DataTable API
TDD WorkflowRed-green iteration with empty rules and scenarios tagged @new
Abstract ModeThe default — compile-time enforcement of step implementations
DocStringsMulti-line input (JSON, plain text) → trailing String parameter
Convention DiscoveryBare @Gherkin2JUnit with co-located feature files
Glob PatternsOne marker class → many feature files via glob
Type RefinementRefine generated Param classes with enums for compile-time safety
Config InheritanceShare options across markers with @Gherkin2JUnitOptions on a base class
Cucumber Annotations@Given / @When / @Then matching with custom method names

Tooling

ExampleWhat it covers
Execution ReporterThe dev.specbinder:execution-reporter module — one JSON file per feature

Running an example

Every example is a self-contained Maven project. After cloning the repo:

cd examples/getting-started/example-1
mvn test

The generated test class appears under target/generated-test-sources/ — open it in your IDE to see what the annotation processor produced.