| name | managing-tests |
| description | Runs, debugs, and fixes Flutter tests including unit tests, widget tests, and Patrol E2E tests. Use when tests fail, need updating after code changes, or when creating new tests. Not for general code debugging or feature implementation. |
| argument-hint | [test-file-path-or-pattern] |
| disable-model-invocation | false |
Managing Tests Skill
Purpose
This skill handles the complete lifecycle of test management:
- Run tests - Execute unit, widget, or Patrol E2E tests
- Analyze failures - Identify why tests fail (API changes, mocks outdated, logic errors)
- Fix tests - Update tests to match current implementation
- Refine test structure - Improve test organization and maintainability
Test Categories
Unit/Widget Tests (test/ directory)
- Standard Flutter tests using
flutter_test
- Mock with
mocktail (mockito-style API)
- Run with:
flutter test test/path/to/test.dart
Patrol E2E Tests (patrol_test/ directory)
- Device/emulator automation tests
- Critical:
test_bundle.dart is auto-generated by patrol_cli
- Run with:
patrol test --target patrol_test/tests/file.dart
Common Issues & Solutions
1. Test API Mismatches
Symptom: "X positional arguments expected by Y, but Z found"
Cause: Function signature changed, tests not updated
Fix: Update test mocks to match new signatures
2. Mocktail argThat Not Found
Symptom: "The function 'argThat' isn't defined"
Cause: Missing mockito-style matcher import
Fix: Mocktail uses different matcher syntax - check current mock patterns in codebase
3. Patrol Import Errors
Symptom: "Target of URI doesn't exist: 'package:patrol/patrol_tester.dart'"
Cause: test_bundle.dart uses runtime-only imports
Fix: Already handled - patrol_test/** is excluded from analysis in analysis_options.yaml
4. Type Inference Warnings
Symptom: "AsyncValue should have explicit type arguments"
Fix: Add explicit generic types to AsyncValue and AsyncData
Workflow
- Identify test type from file path
- Run failing test to see exact error
- Analyze error - is it mock setup, API change, or logic issue?
- Fix incrementally - update one test at a time
- Verify fix - run test again to confirm
- Apply dart fix - run
dart fix --apply for auto-fixes
- Final check -
dart analyze and flutter test
Key Commands
flutter test test/features/scanner_test.dart
flutter test
flutter test -v
patrol test --target patrol_test/tests/full_cycle_test.dart
dart fix --apply
dart analyze
Code Patterns
Mock Setup with Mocktail
class MockCatalogDao extends Mock implements CatalogDao {}
// In setUp:
when(() => mockDao.getProduct(any())).thenAnswer((_) async => mockResult);
Riverpod Provider Tests
final container = ProviderContainer(
overrides: [
catalogDaoProvider.overrideWithValue(mockCatalogDao),
],
);
AsyncValue Type Safety
// Instead of: AsyncValue<dynamic>
// Use: AsyncValue<ScannerState>
Files to Check
test/** - Unit and widget tests
patrol_test/tests/** - E2E test files
patrol_test/robots/** - Robot pattern page objects
pubspec.yaml - Test dependencies
analysis_options.yaml - Already excludes patrol_test/** from analysis
Output Format
After fixing tests, report:
- Files modified: List of test files updated
- Issues fixed: What specific problems were resolved
- Verification: Results of
dart analyze and flutter test
- Remaining issues: Any tests still failing and why