Specification by Example
A collaborative method to specify requirements via concrete examples and turn them into automatable acceptance tests.
Classification
- ComplexityMedium
- Impact areaOrganizational
- Decision typeOrganizational
- Organizational maturityIntermediate
Technical context
Principles & goals
Use cases & scenarios
Compromises
- Examples become detached from implementation and get stale.
- Excessive detail leads to fragile test code.
- Poor workshop facilitation generates irrelevant scenarios.
- Focus on business‑relevant examples rather than technical details.
- Keep examples readable and understandable for business readers.
- Isolate automation logic from domain example text.
I/O & resources
- Business goals and user needs
- Preliminary user stories or features
- Domain experts and developers in the workshop
- Explicit examples with acceptance criteria
- Automated acceptance tests in CI
- Living documentation as reference
Description
Specification by Example is a collaborative technique for defining requirements using concrete examples that become accurate, automatable acceptance tests. Teams create realistic scenarios, remove ambiguities and produce executable specifications. It fosters shared domain models and reduces rework.
✔Benefits
- Improved communication between business and development.
- Early, reproducible feedback via automated acceptance tests.
- Reduced implementation errors and less rework.
✖Limitations
- Requires discipline to maintain and synchronise examples.
- High initial effort in complex domains.
- Not all non‑functional requirements can be expressed via examples.
Trade-offs
Metrics
- Acceptance test coverage
Percentage of critical requirement examples that are executed automatically.
- Cycle time requirements→test
Time from first draft of an example to successful test execution in CI.
- Bug reproducibility
Share of reported bugs that can be reproduced via an example.
Examples & implementations
E-commerce checkout scenarios
Examples describe payment options, multiple items and discounts as executable tests.
Booking flow for travel platform
Scenarios model seat availability, cancellations and pricing rules.
User registration with validation rules
Concrete examples clarify field validation, email verification and error behaviour.
Implementation steps
Bring stakeholders and developers together for example workshops.
Identify core scenarios and formulate them in Given‑When‑Then.
Move examples into a testable artifact in a repository.
Implement automation adapters to make examples executable.
Configure CI pipeline to execute the acceptance suite.
Establish regular reviews and maintenance intervals for living documentation.
⚠️ Technical debt & bottlenecks
Technical debt
- Large collection of stale examples without a cleanup plan.
- Ad‑hoc test adapters that are not reusable.
- Monolithic test suites that force long run times.
Known bottlenecks
Misuse examples
- Using examples to document implementation details rather than requirements.
- Writing every tiny behaviour as a separate example.
- Relying solely on examples for legal requirements.
Typical traps
- Unclear ownership for maintaining examples.
- Tight coupling of tests to fragile UI elements.
- Lack of metrics to measure value.
Required skills
Architectural drivers
Constraints
- • Time budget for workshops is limited.
- • Legacy systems hinder automated verification.
- • Legal requirements may constrain example design.