A community driven cookbook with recipes (i.e., examples) on how to test your flutter application.
There are three pillars of flutter tests:
- unit
- widget
- integration
This cookbook is mostly concerned with 2 and 3.
Currently, flutter_test is used for widget tests, and flutter_driver is used for integration tests. However, it is possible that flutter_driver
could eventually be deprecated, and flutter_test
could be used for both widget and integration tests.
We're moving away from flutter_driver in favour of extending flutter_test to work on devices.
- Hixie
https://github.com/flutter/flutter/issues/7474#issuecomment-558882182
Because of this, the recipes will be split out into two directories: flutter_test
and flutter_driver
- How do I run a flutter test?
- How do I find something?
- How do I test routes?
- How do I drag something?
- How do I open a Drawer?
- How do I send a keyboard action like done or next?
- How do I test an Exception?
- What if I need a BuildContext?
- How do I run a script inside a test?
- How do I mock an async http request?
- How do I mock shared_preferences?
- How do I test an animation?
- How do I run a flutter driver test?
- How do I find something?
- How do I take a screenshot
- How do I dismiss (i.e. pop) a dialog?
- How do I run a script inside of a test?
- How I run multiple test files without restarting app?
This section is a list of external resources that may be useful when exploring how to test your flutter application.
Written
- Flutter UI Testing (with codemagic)
- Mock dependencies using Mockito
- Flutter: Golden tests - compare Widgets with Snapshots
- Testing gestures using Flutter driver
- 60 Days of Flutter: Day 4-5: Widget Testing with Flutter
- Blazingly Fast Flutter Driver Tests
- Developing and testing accessible apps in Flutter
Videos
- Flutter: Deep Dive with Widget Tests and Mockito
- Bloc Test Tutorial - Easier Way to Test Blocs in Dart & Flutter
First of all, thank you. Contributions are encouraged! Please follow the guidelines below.
If you'd like to suggest a recipe, please open an issue and add [recipe-suggestion]
to the beginning of the title.
If you'd like to add a recipe, please add [new-recipe]
to the beginning of your PR's title.
Each recipe should:
- be focused on a specific topic
- be concise
- have runnable tests
- only check in 'meaningful' files
Note: if you want to get an early sense of whether or not your recipe will be accepted, please open a [recipe-suggestion]
issue first.
If you'd like to fix a typo, please add [fix-typo]
to the beginning of your PR's title.
If you'd like to correct an error in an existing recipe, please add [fix-recipe]
to the beginning of your PR's title.
If you'd like to add a link to an external resource, please add [add-resource]
to the beginning of your PR's title.
Copyright © 2020 Matthew Jaoudi
Distributed under the The MIT License (MIT).