This project attempts to setup the test pyramid for a flutter app. The app has been layered as prescribed by ResoCoder blog https://resocoder.com/category/tutorials/flutter/tdd-clean-architecture/.
- Configure both Android emulator, iOS simulator. https://stackoverflow.com/questions/49280884/how-to-set-up-devices-for-vs-code-for-a-flutter-emulator
- Command: F5
- You can choose if you want to run on emulator or simulator. Recommended that we test on both.
From project root (flutter_test_pyramid_spike) run flutter test
in Terminal
From project root (flutter_test_pyramid_spike) run flutter drive --target=test_driver/cart_increment.dart
in Terminal
-
Introduction: https://flutter.dev/docs/testing
-
Unit tests: We have used Mockito for mocking.
-
Widget tests: UI tests similar to Roboelectric. Doesn't require the emulator/simulator to be launched.
-
Integration tests: Functional tests that cover broader flows. Runs as a separate process from the app and talks to the app with the help of a driver
-
Golden tests: UI Snapshot testing for pixel by pixel comparison.
-
Commands: To run various tests see above
All dependencies must be specified in pubspec.yaml
-
App Dependencies
- dartz: ^0.8.7: For using Either data type for functional style error/repsonse handling
- http: ^0.12.0+2: For http calls
- flutter_bloc: ^0.22.1: For adopting the BLoc design pattern (see link below).
- equatable: ^0.6.0: So that we don't have to define equatability. Avoiding boilerplate.
- get_it: ^1.0.3: For dependency injection
-
Test Dependencies
- mockito: ^4.0.0: For mocking. (see link above)
- Flutter clean architecture. https://resocoder.com/category/tutorials/flutter/tdd-clean-architecture/
- BLoc pattern. https://resocoder.com/2019/10/26/flutter-bloc-library-tutorial-1-0-0-stable-reactive-state-management/
- Separation of Concerns(S), Interface Segragation(I), Dependency Inversion(D)
- Functional style error handling using Either (dartz package)
-
Network Images mocking in tests to avoid exceptions being thrown. See
product_list_item_test.dart
. Details here: -
How to solve Not found: 'dart:ui' error while running integration tests on Flutter. Details here:
- Service Locator design
- Should we group golden_tests and integration tests by feature
- Wiremock for mocking network calls
-
Dependency injection for mocking service calls.
-
Generator functions - yeild, yield*, async, async*, sync*
-
RepaintBoundary
-
Scaling UI