I’m initializing the app like
void main() async {
await Initializer.init();
runApp(MyApp());
}
Initializer.init()
initializes all dependencies like Firebase Analytics and register things like Hive TypeAdapters.
My sample tests look like:
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets(
'Sample',
(WidgetTester tester) async {
await Initializer.init();
await tester.pumpWidget(MyApp());
await tester.tap(find.text('Something'));
expect(find.text('180 Results'), findsOneWidget);
},
);
testWidgets(
'Sample 2',
(WidgetTester tester) async {
await Initializer.init();
await tester.pumpWidget(MyApp());
await tester.tap(find.text('Something 2'));
expect(find.text('180 Results'), findsOneWidget);
},
);
}
My problem is that after executing the first test, things that were initialized by Initializer.init()
aren’t disposed correctly.
Is there a way to tell
integration_test
to reset the whole environment every time test is reloaded?Shall I initialize things differently than static
Initializer.init();
Shall I explicitly dispose/unregister all dependencies (sth like
Initializer.dispose()
at the end of every test)? That solution seems to be a nightmare since I'm using many 3rd parties that are not allowing explicit disposing.