Pruebas
Most test scenarios map directly a ProviderContainer APIs: read, invalidate, refresh, listen, y overrides per provider instance.
Test Strategy
Split tests into pure container tests y widget integration tests.
Pure Dart
Use ProviderContainer directly para read/invalidate/refresh assertions
Overrides
Override per provider instance con overrideWith / overrideWithValue
Widget tests
Inject external container y dispose it explicitly
Tip
ProviderContainer.listen does not emit initial value unless fireImmediately: true is specified.
Test Command y Lista de verificaci?n
Run full suite y verify no pending timer leaks en 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.
ejemplo: per-argument override
family-like providers are overridden per instance created de your factory function.
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();
Siguientes pasos
API Referencia
Open quick signatures para ProviderContainer, Ref, AsyncValue, y mutation APIs.
Open API Referencia