Loading topic
ProviderContainer is the right tool for the job, what it does, and how a first test looks. Later chapters build on it with overrides, async providers, listening7 min readflutter_test, can write a basic test with expect, and have used Provider, NotifierProvider, and ref.watch versus ref.read in Riverpod. Examples use Riverpod 2.x APIs (Notifier, NotifierProvider). The container lifecycle works the same way in l6 min readcontainer.read works in a test: when it creates state, what it returns, and how to read each kind of provider. It assumes you can write test and expect cases, you know the basic provider types (Provider, FutureProvider, NotifierProvider), and you know await in D5 min readNotifier holds state and the methods that change it. The logic worth testing sits in those methods: which transitions are allowed, what the initial state is, and how the notifier uses its dependencies. This chapter shows how to test that logic with a ProviderContainer and no widgets.4 min readProviderContainer, so the code under test runs against a stand-in you cont5 min readProviderContainer. It assumes you can write tests with flutter_test, know the basic Riverpod providers (Provider, FutureProvider, NotifierProvider), and are comfortable 5 min readflutter_test (test, expect, addTearDown). It also assumes you know how to create a ProviderContainer and override a provider. You should be comfortable with async/await. Here you will test a FutureProvider through its three outcomes: load6 min readcontainer.read returns a provider's value at one moment. Many bugs involve a sequence of values: a loading state that never appears, a state that flips twice when it should flip once, or an update that fires for an unchanged value. This chapter shows how to record that sequence with `container.lis5 min readtest, expect, and addTearDown. It also assumes you have seen ProviderContainer, container.read, and container.listen from earlier chapters. Here you will learn why an auto-dispose provider can lose its6 min readProviderContainer, then register container.dispose with addTearDown. This chapter turns those lines into one small helper. It also covers where the helper should live, how to extend it, and the mistakes that make 6 min readProviderContainer. This chapter applies the same overrides to widget tests. You will wrap a widget in a ProviderScope, give it fake dependencies, and check what appears on screen.5 min readflutter_test (test, expect, group, addTearDown). It also assumes you know Provider, FutureProvider, and NotifierProvider, the `createContain5 min read