Closed StanevPrime closed 1 day ago
This could also help with the test checking: https://stackoverflow.com/questions/59028609/how-to-find-if-we-are-running-unit-test-in-dart-flutter
Platform.environment.containsKey('FLUTTER_TEST');
is a boolean that returns true
when it's executed by a test and false
otherwise.
To work on Web, iOS and Android, it should be imported from universal_io/io.dart
.
I tested it on mobile and web and it works with universal_io: ^2.2.2
, which is the latest version for now. From this comment it looks like it wasn't working on previous versions.
So the Option 2 with global variable is a good option.
I discovered that if multiple pages/widgets implement the same type of widget with *WithDependencies
, they share same instance of the widget and they don't if initialize it with the class without the dependencies.
Adding an extra dependency (universal_io) is not a good option from my perspective, since it increases the maintenance cost of the rx_bloc_cli.
It was decided to proceed with the option 2 based on the following benefits:
isInTestMode
global variable will be accessible for all kind of tests, including unit and golden onesisInTestMode
will be set automatically @DDavidPrime, @nikolay-vasilev-prime
As a developer I want when the widget tree is built during the golden tests execution the dependencies of smart widgets such as BloCs, Services etc to be not added to the widget tree so that I can add them as mock objects
ACs
Reference implementation:
Option 1: flutter_test_config.dart
Option 2
is_in_test_mode_io_available.dart
is_in_test_mode_io_not_available.dart
app_constants.dart
Documentation: https://dart.dev/guides/libraries/create-packages#conditionally-importing-and-exporting-library-files
Option 3
Define a variable in the test run command and have it as a global constant with default value in the app,
app_constants.dart
Run All Tests configuration arguments
Refferance: https://stackoverflow.com/a/63723815
Option 4
Platform.environment.containsKey('FLUTTER_TEST');
is a boolean that returnstrue
when it's executed by a test andfalse
otherwise. To work on Web, iOS and Android, it should be imported fromuniversal_io/io.dart
.It is tested on mobile and web and it works withuniversal_io: ^2.2.2