Learn ยท 04 of 5
Scenarios: make the slice testable
A scenario lives beside its workflow and describes one business rule using typed steps.
| Workflow | Given | When | Then | Cardinality |
|---|---|---|---|---|
| State Change | Event | Command | Event or Error | zero or more given, one when, one or more then |
| State View | Event | none | Read Model or Error | one or more given, zero when, one or more then |
| Automation / Translation | Event or Read Model | Processor or Command | Event or Error | one when, one or more then |
Each step has one typed target. An error target contains a literal string.
State Change scenario
An error path uses a different then target. An optional comment records the business rule:
State View scenario
For example: given Student Registered, then Students to Welcome.
State View: one or more Event given steps, no when, and one or more Read Model or Error then steps.
Working from an older draft? See the migration guide for the removed Query form.
Automation / Translation scenarios
given targets an Event or Read Model, when targets a Processor or Command, and then targets an Event or Error.
Faded exercise: complete a State View
Fill in each ??? before opening the answer.