/flutter-clean-riverpod-skills:flutter-testingfrom flutter-clean-riverpod-skills
Provides testing patterns for Flutter apps using Riverpod, Result-based repositories, and contract boundaries. Covers unit tests for data sources/repositories/notifiers, widget tests with provider overrides, listener tests with recording fakes, golden tests, and mock vs fake decision guidance.
Ships in flutter-clean-riverpod-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The architecture makes testing cheap: every boundary is a contract you can override. Test behaviour at the boundaries, not implementation details.
test/
├── helpers/ test_container.dart, pump_app.dart, fakes, helpers.dart (barrel)
├── core/ mirrors lib/core
├── features/<feature>/ mirrors lib/features/<feature>; goldens/ beside the test
└── shared/
One test file per source file, named <file>_test.dart. Group by class.
| Use | When |
|---|---|
| Recording fake (a hand-written class that implements the contract and stores what it received) | Stateful app-owned contracts: AnalyticsService, ErrorTrackingService, NotificationService. Assertions read as "this event was tracked". |
mocktail mock | A repository or data-source contract with canned answers: when(repo.getDashboard).thenAnswer((_) async => Success(dashboard)). |
Fake ApiClient | Testing a remote data source: throw an ApiException, assert the Result. Never mock Dio here. |
Mock Dio | Only in the DioApiClient test itself. |
If you find yourself mocking an SDK inside a feature test, the SDK is not
behind a contract (see flutter-sdk-contracts).
assets/)test_container.dart: createContainer(overrides:) disposes itself and turns
retry off. Riverpod 3 retries failing providers with backoff by default,
which makes failure assertions slow and flaky.pump_app.dart: tester.pumpApp(widget, overrides:) mounts under the real
theme and localizations and returns the container.recording_analytics_service.dart: from the flutter-sdk-contracts assets.1. Data source: failure mapping
test('maps 401 to AuthFailure', () async {
final api = _FakeApiClient(throws: const ApiResponseException(statusCode: 401));
final result = await ProfileRemoteDataSourceImpl(api).fetchProfile();
expect(result.exceptionOrNull(), isA<AuthFailure>());
});
Cover: success, 401/403 → AuthFailure, 422 → ValidationFailure, 5xx →
ServerFailure, connection error → NetworkFailure, timeout → NetworkFailure,
anything else → UnknownFailure.
2. Repository: model → entity
Fake the data source, return a model, assert the entity. Also assert a failure is passed through unchanged.
3. Notifier
test('loads items from the repository', () async {
final repo = _MockItemRepository();
when(repo.getPage).thenAnswer((_) async => Success(page));
final container = createContainer(
overrides: [itemRepositoryProvider.overrideWithValue(repo)],
);
final state = await container.read(itemsProvider.future);
expect(state.items, page.items);
});
data/ is never touched.autoDispose providers, hold a listener (keepAlive helper) or the
provider can be disposed between reads.learningProvider.overrideWith(_RecordingLearningNotifier.new).4. Submission notifier: dispose mid-flight
test('survives disposal while the action is in flight', () async {
final completer = Completer<Result<String>>();
final subscription = container.listen(provider, (_, _) {});
final pending = container.read(provider.notifier).submit(completer.future);
subscription.close(); // the screen goes away
await container.pump();
completer.complete(const Success('late'));
await expectLater(pending, completion(isA<Success<String, AppFailure>>()));
});
Without the ref.mounted guard this throws after disposal.
5. Widget
testWidgets('shows an error with a retry', (tester) async {
await tester.pumpApp(
const ItemsPage(),
overrides: [itemRepositoryProvider.overrideWithValue(_FailingRepository())],
);
await tester.pumpAndSettle();
expect(find.text('Try again'), findsOneWidget);
});
6. Listener widget
Mount only the listener over an empty child with UncontrolledProviderScope,
override the contracts (recording analytics, mock repository), drive the state
and assert:
final analytics = RecordingAnalyticsService();
final container = createContainer(overrides: [
analyticsServiceProvider.overrideWithValue(analytics),
]);
await tester.pumpWidget(UncontrolledProviderScope(
container: container,
child: const ItemsListeners(child: SizedBox()),
));
container.read(itemSubmissionProvider.notifier).add();
await tester.pump();
expect(analytics.events.single, isA<ItemChangedEvent>());
End by unmounting (await tester.pumpWidget(const SizedBox())) before the
container is disposed.
7. DioApiClient
Mock Dio and assert exception mapping: timeouts and connection errors →
ApiConnectionException, bad responses → ApiResponseException with status
and code, anything else → ApiUnknownException. Stub the same method the
adapter calls (dio.request<Map<String, dynamic>>(...) in the reference
adapter).
8. Goldens — assets/golden_test_template.dart
@Tags(['golden'])) so they can be run or skipped separately.devicePixelRatio.flutter test --tags golden --update-goldens.9. Pin framework behaviour you rely on
When a feature depends on a library behaviour that is not yours to guarantee (for example, a failed refetch keeps the previous value so pull-to-refresh can report the error without blanking the list), write a small test that asserts it:
expect(state, isA<AsyncError<String>>());
expect(state.hasValue, isTrue); // failed AND still holds the old value
A package upgrade that drops it then fails a test instead of showing up as vanishing content on a bad connection, far from any code you changed.
Dio or
Firebase, a contract is missing.verify(...).called(n) unless the call count is the behaviour.sleep. Use tester.pump(duration), fake_async, or container.pump().ProviderContainer (addTearDown).check_boundaries.sh from
flutter-feature-scaffold; tests are not the place for import hygiene.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub ethiel97/flutter-clean-riverpod-skills --plugin flutter-clean-riverpod-skills6 skills in this plugin
/flutter-feature-scaffoldUse when adding a new feature or module to a Flutter app that follows feature-first Clean Architecture (data / domain / presentation) with Riverpod 3 and no code generation for providers, when deciding which layer or folder a file belongs in, or when reviewing dependency direction between layers. Provides the folder layout, per-layer rules, barrel conventions, build order and a scaffold script./flutter-result-errorsUse when writing or reviewing Flutter data-layer, repository or provider code that can fail, when adding Result/AsyncResult types or failure types, when mapping exceptions to user-facing errors, or when an exception is crossing a layer boundary. Sets up a sealed AppFailure taxonomy, Result typedefs over result_dart, one catch boundary (RemoteDataSourceGuard) and the way presentation folds failures./flutter-riverpod3Use when writing or reviewing Riverpod 3 code in a Flutter app WITHOUT code generation - choosing a provider type, wiring dependency injection, writing Notifier or AsyncNotifier classes, using ref.watch / read / listen / select, handling disposal, mounted checks and automatic retry, or when someone proposes riverpod_generator, @riverpod, StateNotifier, Bloc, GetIt or the provider package./flutter-sdk-contractsUse when adding, replacing or touching any third-party SDK or platform plugin in a Flutter app (Firebase, Sentry, PostHog, Dio, secure storage, shared_preferences, notifications, share, clipboard, permissions, purchases), or when feature code imports an SDK directly. Defines application-owned contracts (ports), adapters, no-op/composite/recording implementations and their Riverpod wiring./flutter-ui-side-effectsUse when a Flutter widget needs navigation, snackbars, dialogs, analytics or any one-shot reaction to a state change, when button callbacks contain context.router / ScaffoldMessenger / analytics calls, when error copy must be shown for a failed action, or when adding a <Feature>Listeners widget. Covers ref.listen listener widgets, per-attempt submission state and mapping failures to user-facing text.Other plugins' skills for the same job