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.
| Example | What it covers |
|---|---|
| Hello World | The smallest possible feature — one scenario, plain steps, no parameters |
| Step Parameters | Type inference for quoted values: String, Integer, Long, Double, Boolean, Character |
| Implementing Steps | End-to-end working example with real assertions and shared state |
| Rules | Gherkin Rule blocks → JUnit @Nested test classes |
| Background | Feature- and rule-level Background blocks → @BeforeEach |
| Scenario Outline | Parameterized scenarios → JUnit @ParameterizedTest with @CsvSource |
| Tags | Gherkin tags → JUnit @Tag for selective execution |
| Convention Discovery | Bare @Gherkin2JUnit with co-located feature files |
Common use cases
Patterns that come up beyond the basics.
| Example | What it covers |
|---|---|
| Typed Data Tables | The default LIST_OF_OBJECT_PARAMS mode — typed inner classes |
| DocStrings | Multi-line input (JSON, plain text) → trailing String parameter |
| Sharing Steps via a Base Class | Put common step implementations in a base class the marker extends |
| Type Refinement | Refine generated Param classes with enums for compile-time safety |
| TDD Workflow | Red-green iteration with empty rules and scenarios tagged @new |
| Glob Patterns | One marker class → many feature files via glob |
| Config Inheritance | Share options across markers with @Gherkin2JUnitOptions on a base class |
Going further
Trickier, more advanced territory — patterns that lean on deeper JUnit or SpecBinder mechanics.
| Example | What it covers |
|---|---|
| Concrete Mode | Opt out of the default abstract mode — a directly-runnable class with failing stubs for unimplemented steps |
| Parameter Resolution | JUnit-resolved step parameters — TestInfo, @TempDir, and custom ParameterResolvers |
| Organizing Steps into Interfaces | Group step methods into domain interfaces the marker implements |
| Execution Reporter | The dev.specbinder:execution-reporter module — one JSON file per feature |
| Cucumber Data Tables | The CUCUMBER_DATA_TABLE mode for Cucumber's DataTable API |
| Cucumber Annotations | @Given / @When / @Then matching with custom method names |
| Build-Log Diagnostics | Tune the annotation processor's build-log output with the verbosity option |
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.