Skip to main content

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 failing noScenariosInRule() test
  • Empty Scenarios (no steps) generate a failing Assertions.fail("Scenario has no steps") test
  • Both are tagged @new by 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

  1. List Rules — write just the rule titles to outline the business domain.
  2. Compile — each empty rule becomes a failing @Test tagged @new.
  3. Add scenario titles under the first rule — still no steps.
  4. Compile — each empty scenario becomes a failing @Test tagged @new.
  5. Add steps to one scenario — it now generates step methods.
  6. Implement the step methods.
  7. Green — that scenario passes.
  8. 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

OptionDefaultWhat it does
emptyScenarioBehaviorFAILFAIL, SKIP, or COMPILATION_ERROR for scenarios with no steps
emptyRuleBehaviorFAILFAIL, 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