98680825a7
Adds a comprehensive opencode skill under .opencode/skills/programming-patterns/
covering 90+ design, architectural, concurrency, and functional patterns.
- 108 files, 33,500+ lines across 13 reference categories
- Every pattern: pseudocode + tested Python + Go + JavaScript implementations
- All 239 code blocks verified passing (85 Python, 76 Go, 78 JS)
- 1,569-line SKILL.md with:
- Master decision tree (all 14 categories with multi-pattern suggestions)
- 34 situation-specific decision trees covering every programming scenario
(new feature, refactoring, REST API, CLI, data pipeline, rule engine,
external integration, performance, memory, notifications, plugins,
caching, events, auth, reporting, vendor lock-in, domain model,
business rules, observability, file I/O, scheduling, testability,
third-party libs, concurrency, complex domain interactions)
- 12 compound pattern-combination scenarios with full architecture maps
(e-commerce checkout, REST endpoint, background jobs, real-time dashboard,
microservice resilience, ML pipeline, text editor, legacy migration,
multi-tenant SaaS, document approval, financial transactions, chat)
- 'When Am I Allowed to Skip Patterns?' mandate table (answer: never)
- Quick pattern lookup tables for all 90+ patterns
- Complete reference index
2.1 KiB
2.1 KiB
Testing Patterns
Overview
Testing patterns provide structured approaches to writing reliable, maintainable, and expressive tests. They address common challenges: isolating units under test, structuring test logic clearly, managing complex test data, and abstracting UI interactions for end-to-end tests.
Pattern Comparison
| Pattern | Purpose | Scope | Key Benefit |
|---|---|---|---|
| Test Doubles | Replace real dependencies with controlled substitutes | Unit / Integration | Isolation from external systems |
| Arrange-Act-Assert | Structure each test in three clear phases | Unit / Integration | Readability and consistency |
| Given-When-Then | Express tests as BDD scenarios | Acceptance / BDD | Business-readable specifications |
| Page Object | Encapsulate UI page structure behind an API | UI / E2E | Decouple tests from page layout |
| Test Data Builder | Construct complex test fixtures fluently | Unit / Integration | Reduce boilerplate, improve clarity |
When to Use Which
- Need to isolate a unit from its dependencies? Use Test Doubles (mock, stub, spy, fake, dummy).
- Want a simple, consistent test layout? Use Arrange-Act-Assert for any unit or integration test.
- Writing acceptance tests with stakeholders? Use Given-When-Then for natural-language scenarios.
- Testing web UIs that change layout frequently? Use Page Object to centralise selectors.
- Creating many similar but slightly different test objects? Use Test Data Builder for fluent construction.
Relationships Between Patterns
- Arrange-Act-Assert and Given-When-Then are structural alternatives; AAA is more common in unit tests, GWT in BDD.
- Test Doubles are used inside the "Arrange" / "Given" phase of either structure.
- Test Data Builder simplifies the "Arrange" / "Given" phase when fixtures are complex.
- Page Object is typically combined with AAA or GWT for UI tests.
Further Reading
- xUnit Test Patterns by Gerard Meszaros
- Growing Object-Oriented Software, Guided by Tests by Freeman & Pryce
- Martin Fowler's "Mocks Aren't Stubs" article