flutter-tester
Use when creating, writing, fixing, or reviewing tests in a Flutter project. Covers unit tests, widget tests, integration tests, Riverpod provider testing, and Mockito mocking. Provides Given-When-Then patterns, layer isolation strategies, and test setup for GetIt, SharedPreferences, and FakeDatabase.
What this skill does
# Flutter Tester
## Requirements
- Flutter project with `flutter_test` dependency
- Works with Riverpod, Mockito, and GetIt
- Run `dart run build_runner build` to generate mocks after adding `@GenerateMocks` annotations
- Compatible with FVM (`fvm flutter test` instead of `flutter test`)
## Overview
Test each architectural layer in isolation using Given-When-Then structure. Always test both success and error paths. Never mock providers — override their dependencies instead.
## Reference Files
Load the relevant file based on what you're testing:
| What you're testing | Reference file |
| --- | --- |
| Repository, DAO, Service logic | `references/layer_testing_patterns.md` |
| Widget UI, interactions, dialogs, navigation | `references/widget_testing_guide.md` |
| Riverpod provider state, mutations, lifecycle | `references/riverpod_testing_guide.md` |
## Core Principles
### 1. Layer Isolation
Test each layer against its own mocked dependencies:
| Layer | What to test | What to mock |
| --- | --- | --- |
| **Repository** | Data coordination between sources | DAOs, APIs, Logger |
| **DAO** | Database CRUD operations | Use real in-memory DB, mock Logger |
| **Provider** | State management and transitions | Services, Repositories |
| **Service** | Business logic and workflows | Repositories, Network clients |
| **Widget** | UI behaviour and interactions | Provider dependencies (via overrides) |
### 2. Given-When-Then Structure
```dart
test('Given valid data, When fetchUsers called, Then returns user list', () async {
// Arrange (Given)
when(mockDAO.fetchAll()).thenAnswer((_) async => expectedUsers);
// Act (When)
final result = await repository.fetchUsers();
// Assert (Then)
expect(result, equals(expectedUsers));
verify(mockDAO.fetchAll()).called(1);
});
```
### 3. Test Organisation
```dart
group('UserRepository', () {
group('fetchUsers', () {
setUp(() { /* init mocks, register with GetIt */ });
tearDown(() => GetIt.I.reset()); // Always reset GetIt
test('Given success ... When ... Then ...', () { });
test('Given error ... When ... Then ...', () { });
});
});
```
## Standard Test Setup
### Generate Mocks
```dart
@GenerateMocks([IUserDAO, IUserAPI, ILogger])
void main() { ... }
```
Run `dart run build_runner build` after modifying `@GenerateMocks`.
### Register with GetIt
```dart
setUp(() {
mockDAO = MockIUserDAO();
mockLogger = MockILogger();
GetIt.I
..registerSingleton<IUserDAO>(mockDAO)
..registerSingleton<ILogger>(mockLogger);
});
tearDown(() => GetIt.I.reset()); // Critical — always reset
```
### Fakes vs Mocks
- **Fakes** (`class FakeLogger extends ILogger`) — silent stubs; use when you don't need to verify calls
- **Mocks** (`MockILogger`) — use when you need `when()`, `verify()`, or `thenThrow()`
## Quick Reference
| Scenario | Key pattern |
| --- | --- |
| Test a repository | Mock DAO + API → inject into repository constructor |
| Test a DAO | `FakeDatabase` or `openInMemoryDatabase()` in setUp, delete table in tearDown |
| Test a Riverpod provider | `createContainer(overrides: [serviceProvider.overrideWith(...)])` |
| Test a widget | Set screen size, use `find.byKey()`, call `pumpAndSettle()` |
| Test a loading state | Use `Completer`, `pump()` to assert loading, complete, `pump()` again |
| Test platform-specific UI | `debugDefaultTargetPlatformOverride = TargetPlatform.iOS` — reset after |
| Test GoRouter navigation | `FakeGoRouter` + `MockGoRouterProvider` |
## Running Tests
```bash
flutter test --coverage # All tests with coverage
flutter test test/path/to/test.dart # Specific file
flutter test --plain-name "Given valid data" # Filter by name
genhtml coverage/lcov.info -o coverage/html # Generate HTML coverage report
# Prefix any command with `fvm` if using Flutter Version Manager
```
## Common Mistakes
| Mistake | Fix |
| --- | --- |
| Mocking a provider directly | Override its dependencies: `provider.overrideWith(...)` |
| Missing `GetIt.I.reset()` in `tearDown` | Tests pollute each other — always reset |
| `await Future.delayed()` in tests | Use `await tester.pumpAndSettle()` or `Completer` instead |
| Finding widgets by text string | Use `find.byKey(const Key('name'))` — stable across text changes |
| No screen size in widget tests | Add `tester.view.physicalSize = const Size(1000, 1000)` |
| Not resetting `debugDefaultTargetPlatformOverride` | Set to `null` at the end of the test |
| `tearDown()` without a lambda | Write `tearDown(() async { ... })` not `tearDown() async { ... }` |
## Test Checklist
**Setup & Mocking:**
- [ ] Dependencies mocked (not providers)
- [ ] SharedPreferences mocked if used
- [ ] `GetIt.I.reset()` in `tearDown`
- [ ] Streams closed in `tearDown`
- [ ] Controllers disposed in `tearDown`
**Widget Tests:**
- [ ] Keys added to source widgets and used in `find.byKey()`
- [ ] Screen size set (`physicalSize` + `devicePixelRatio`)
- [ ] Platform overrides reset (`debugDefaultTargetPlatformOverride = null`)
- [ ] Navigation verified if applicable
**Test Coverage:**
- [ ] Success and failure paths covered
- [ ] Edge cases tested (null, empty, max values)
- [ ] Loading and error states tested
- [ ] Async handled correctly (no `Future.delayed`)
**Code Quality:**
- [ ] Given-When-Then naming used
- [ ] `verify()` or `verifyNever()` where appropriate
- [ ] Tests are isolated and deterministic
Related in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.