Setting up the project
First of all, you need to create a top-level folder called test
; this is where we’re going to spend most of our time. Then, you need to add a new dependency to the pubspec.yaml
file since we’re going to use it in the next section. Once you’ve done this, your dev_dependencies
should be as follows (if it’s the case, make sure that you update them to their latest versions):
dev_dependencies: dart_code_metrics: ^4.8.1 flutter_lints: ^1.0.4 flutter_test: sdk: flutter golden_toolkit: ^0.12.0
Finally, we need to create a useful widget that wraps a common configuration that’s required by all the widgets we’re going to test. Since the app is based on a material design, our class is going to wrap a MaterialApp
and a Scaffold
widget. Place this widget inside the test
folder and name it whatever you want; for example, mock_wrapper.dart
:
class MockWrapper...