???
Most test scenarios map directly ? ProviderContainer APIs: read, invalidate, refresh, listen, ? overrides per provider instance.
Test Strategy
Split tests into pure container tests ? widget integration tests.
Pure Dart
Use ProviderContainer directly ? read/invalidate/refresh assertions
Overrides
Override per provider instance ?? overrideWith / overrideWithValue
Widget tests
Inject external container ? dispose it explicitly
Tip
ProviderContainer.listen does not emit initial value unless fireImmediately: true is specified.
Test Command ? ?????
Run full suite ? verify no pending timer leaks ?? autoDispose scenarios.
Command
flutter test
Checklist
- Dispose externally injected ProviderContainer in tearDown.
- Use fireImmediately: true when your listener assertions need initial state.
- For autoDispose tests, advance fake time beyond autoDisposeDelay.
??: per-argument override
family-like ????? are overridden per instance created ?? your factory function.
product_provider_test.dart
class ProductById extends Provider<Product> {
ProductById(this.id) : super.args((id,));
final String id;
@override
Product build(ref) {
final repo = ref.watch(productRepoProvider);
return repo.fetch(id);
}
}
final container = ProviderContainer(
overrides: [
productByIdProvider('a').overrideWithValue(const Product(id: 'a', name: 'stub')),
],
);
// assert and cleanup
container.dispose();
This pattern mirrors the README ? upstream tests ?? miniriverpod repository.
Widget tests should unmount widgets before disposing external containers.
Use fake_async ? validate autoDispose delays ? keepAlive behavior.