Agent skill
flutter-test
Generate high-quality Flutter tests for BLoC-based applications.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/flutter-test
Metadata
Additional technical details for this skill
- short description
- Generate unit and widget tests using bloc_test and mocktail.
SKILL.md
Generate Flutter tests following best practices for BLoC-based state management.
Required Test Dependencies
Ensure the project has these dev_dependencies before generating tests:
dev_dependencies:
flutter_test:
sdk: flutter
bloc_test: ^10.0.0
mocktail: ^1.0.4
Default mocking stack for this skill remains:
bloc_testfor BLoC/Cubit behavior tests.mocktailfor repositories/services and interaction verification.
Requirements
General
- Use Flutter test conventions and idioms.
- Always separate:
- Unit tests (BLoC, Cubit, business logic)
- Widget tests (UI behavior, rendering, interaction)
- Tests must be deterministic and isolated.
- Always use English for test names and comments.
- Prefer readability and clarity over brevity.
Unit Test Requirements (State Management)
-
Use
bloc_testfor allBlocorCubittesting. -
Tests must:
- Clearly describe initial state, action, and expected states
- Use
blocTest<TBloc, TState>
-
Each public event or method must have:
- At least one success case
- At least one failure or edge case (if applicable)
-
Avoid testing UI-related logic in unit tests.
-
Use
mocktailfor mocking dependencies:- Repositories
- Data sources
- External services
-
Do NOT use real implementations in unit tests.
Widget Test Requirements
- Use
flutter_testwithWidgetTester. - Widget tests must:
- Verify rendered UI states (loading, success, error)
- Test user interactions (tap, input, scroll)
- Assert visible behavior, not implementation details
- Inject mocked BLoCs using:
BlocProvider.value- or
MultiBlocProvider
- Avoid golden tests unless explicitly requested.
Assertions & Style
- Prefer:
expectfor standard assertionsverify/verifyNeverfrommocktailfor interaction checks
- Avoid excessive
pumpAndSettle; prefer explicitpumpdurations. - Use descriptive test names:
"emits [Loading, Success] when fetch is successful"
Coverage Guidelines
- Aim for minimum ≥80% coverage at the package or feature level.
- Coverage must include:
- All major BLoC state transitions
- At least one widget test per critical UI state
- Do not introduce meaningless assertions just to increase coverage.
- If ≥80% coverage cannot be achieved without testing private details:
- Explain briefly why
- Suggest a refactor (e.g. extract logic into BLoC or service)
Output Expectations
- Generate complete and runnable test files.
- Follow Flutter naming conventions:
*_bloc_test.dart*_widget_test.dart
- Include all required imports.
- Separate Arrange / Act / Assert clearly.
- Output test code only unless explanation is explicitly requested.
When to Load References
- Detailed technical reference: REFERENCE.md.
Unit Tests (BLoC / Cubit)
- BLoC testing patterns: unit_bloc_testing.md
- Mocking with mocktail: mocktail.md
Widget Tests
- Widget testing fundamentals: widget_testing.md
- Testing BLoC-powered widgets: bloc_widget_testing.md
Additional Guidelines
- Prefer testing behavior over structure.
- Avoid testing Flutter framework internals.
- Do not mock Flutter SDK classes unless unavoidable.
- If a widget is hard to test:
- Explain why briefly
- Suggest architectural improvement (e.g. push logic into BLoC).
For auth output contract and concrete auth examples, see REFERENCE.md.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?