skills/flutter-tdd/SKILL.md
Test-Driven Development for Flutter: red-green-refactor cycle for domain entities, value objects, use cases, repositories, and Riverpod notifiers. Trigger: When writing unit tests, implementing TDD, creating mocks, or testing business logic in the Flutter app.
npx skillsauth add 333-333-333/agents flutter-tddInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
| Pattern | Rule |
|---------|------|
| Test FIRST | Write the failing test before production code. Always. |
| Red -> Green -> Refactor | Fail -> pass -> clean up. Never skip a step. |
| Mirror structure | test/ mirrors lib/ exactly |
| File naming | foo.dart -> foo_test.dart |
| Mocks via interfaces | Domain repository interfaces ARE the mock boundary — no mockito needed for simple cases |
| No test pollution | Each test is independent, no shared mutable state |
| group() for context | Use group() to organize related tests |
| Riverpod: use ProviderContainer | Create isolated containers per test |
1. RED — Write a test that describes the desired behavior. Run it. It MUST fail.
2. GREEN — Write the MINIMUM code to make the test pass. Nothing more.
3. REFACTOR — Clean up while keeping tests green.
4. REPEAT
1. DESCRIBE the behavior you want as a test
2. AI writes the failing test
3. Run it — confirm RED
4. AI writes the implementation
5. Run it — confirm GREEN
6. AI refactors if needed
7. Run it — confirm still GREEN
mobile/
test/
features/
auth/
domain/
entities/
user_test.dart
value_objects/
email_test.dart
password_test.dart
application/
use_cases/
login_use_case_test.dart
presentation/
providers/
auth_state_provider_test.dart
infrastructure/
repositories/
auth_repository_impl_test.dart
booking/
domain/
application/
presentation/
infrastructure/
shared/
domain/
value_objects/
money_test.dart
helpers/
mocks.dart # Shared mock implementations
test_providers.dart # Riverpod test overrides
See assets/booking_test.dart
See assets/email_test.dart
See assets/mocks.dart
For more complex mocking needs, use mocktail:
See assets/mocks_mocktail.dart
See assets/login_use_case_test.dart
See assets/auth_state_provider_test.dart
See assets/async_notifier_test.dart
When using fpdart or dartz for Either<Failure, T>:
See assets/either_test.dart
# Run all unit tests
flutter test
# Run specific test file
flutter test test/features/auth/domain/entities/user_test.dart
# Run tests matching a name pattern
flutter test --name "login"
# Run with coverage
flutter test --coverage
# View coverage report (install lcov first: brew install lcov)
genhtml coverage/lcov.info -o coverage/html
open coverage/html/index.html
# Run tests in a specific directory
flutter test test/features/auth/
# Watch mode (re-run on changes) — requires flutter_test_watch or similar
# Not built-in; use: find test -name '*_test.dart' | entr flutter test
See assets/pubspec_dev_deps.yaml
| Don't | Do |
|-------|-----|
| Write code first, tests later | Write test FIRST (red), then code (green) |
| Test implementation details | Test behavior — inputs and outputs |
| Shared mutable state between tests | Fresh setUp() per test |
| Import infrastructure in domain tests | Mock via interfaces |
| Skip tearDown for ProviderContainer | Always container.dispose() |
| One giant test function | group() + focused test() with descriptive names |
| Use print() for debugging tests | Use expect() with clear matchers |
| Mock everything | Only mock external boundaries (repos, APIs) |
testing
Review Flutter components and screens for UX/UI compliance. Trigger: When user invokes /ux-review command or requests UX audit.
development
TypeScript strict patterns and best practices. Trigger: When implementing or refactoring TypeScript in .ts/.tsx (types, interfaces, generics, const maps, type guards, removing any, tightening unknown).
testing
Testing philosophy and strategy for every feature: test pyramid, mandatory levels per change type, completion checklist, and skill delegation. Trigger: When planning tests for a feature, reviewing test coverage, defining acceptance criteria, or asking what tests a change needs.
development
Terraform security practices: sensitive variables, secret management, state protection, .gitignore patterns, and CI/CD credential handling. Trigger: When handling secrets in Terraform, configuring state backends, reviewing .gitignore for Terraform, or setting up CI/CD pipelines for infrastructure.