Testing async Code and Streams
Await futures and verify event sequences.
Async Needs Care
Lots of real code returns a Future. If a test forgets to wait, it may pass before the work even finishes. ⏳
Return or await
The runner waits when your test body is async and you await the work, or when you return the Future directly.
test('loads user', () async {
final u = await fetchUser();
expect(u.name, 'Ada');
});All lessons in this course
- Your First test and expect
- group, setUp, and tearDown
- Testing async Code and Streams
- Mocks, Fakes, and Coverage