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.dartis auto-generated bypatrol_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<dynamic> 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 --applyfor auto-fixes - •Final check -
dart analyzeandflutter test
Key Commands
# Run specific test flutter test test/features/scanner_test.dart # Run all tests flutter test # Run with verbose output flutter test -v # Run Patrol test patrol test --target patrol_test/tests/full_cycle_test.dart # Fix auto-fixable issues dart fix --apply # Check types 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 analyzeandflutter test - •Remaining issues: Any tests still failing and why