TDD Workflow
Iterative red-green development backed by failing tests generated from incomplete feature files.
Source: examples/common-use-cases/example-3 on GitHub.
What this demonstrates
- Empty
Rules (no scenarios) generate a failingnoScenariosInRule()test - Empty
Scenarios (no steps) generate a failingAssertions.fail("Scenario has no steps")test - Both are tagged
@newby default — easy to filter or display in your IDE - Scenarios with steps still generate normal step methods
- A single feature can mix complete and incomplete scenarios
The TDD iteration cycle
- List Rules — write just the rule titles to outline the business domain.
- Compile — each empty rule becomes a failing
@Testtagged@new. - Add scenario titles under the first rule — still no steps.
- Compile — each empty scenario becomes a failing
@Testtagged@new. - Add steps to one scenario — it now generates step methods.
- Implement the step methods.
- Green — that scenario passes.
- Repeat for the next scenario, then the next rule.
Generated output for a mixed feature
public abstract class ShoppingCartScenarios extends ShoppingCartFeature {
// Rule with no scenarios — fails immediately
@Nested
@Tag("new")
@DisplayName("Rule: Cannot checkout with an empty cart")
public class Rule_1 {
@Test
public void noScenariosInRule() {
Assertions.fail("Rule doesn't have any scenarios");
}
}
@Nested
@DisplayName("Rule: Free shipping applies to orders over 50 euros")
public class Rule_2 {
// Scenario with no steps — fails immediately
@Test
@Tag("new")
@DisplayName("Scenario: Free shipping when subtotal exceeds threshold")
public void scenario_1() {
Assertions.fail("Scenario has no steps");
}
}
@Nested
@DisplayName("Rule: Discount codes apply a percentage reduction")
public class Rule_3 {
// Scenario with steps — normal generated method calls
@Test
@DisplayName("Scenario: Apply a valid discount code")
public void scenario_1() {
myCartSubtotalIs$p1(100.00);
iApplyDiscountCode$p1("SAVE10");
theCartSubtotalShouldBe$p1(90.00);
}
}
}
Relevant options
| Option | Default | What it does |
|---|---|---|
emptyScenarioBehavior | FAIL | FAIL, SKIP, or COMPILATION_ERROR for scenarios with no steps |
emptyRuleBehavior | FAIL | FAIL, SKIP, or COMPILATION_ERROR for rules with no scenarios |
tagForEmptyScenarios | "new" | Tag added to empty scenarios (set to "" to disable) |
tagForEmptyRules | "new" | Tag added to empty rules (set to "" to disable) |
See Configuration for the full list.
Run it
cd examples/common-use-cases/example-3
mvn test