working with tests in flutter and with the new integration tests package didn't find anything that could help me.
My problem is that I need to run several tests, but when the first test ends or the second test fails, because when the test ends, the application does not restart immediately. My code is like this: and I don't know if this is the best way to do it.
void main() {
(IntegrationTestWidgetsFlutterBinding.ensureInitialized()
as IntegrationTestWidgetsFlutterBinding)
.defaultTestTimeout = const Timeout(Duration(minutes: 2));
WelcomeTester welcomeTester;
LoginTester loginTester;
group('e2e integration test', () {
testWidgets('Test case 1',
(WidgetTester tester) async {
await app.main();
await tester.pumpAndSettle(const Duration(seconds: 5));
welcomeTester = WelcomeTester(tester);
loginTester = LoginTester(tester);
await welcomeTester.checkScreenOpenedByKey(WelcomeKeys.screenWelcomePage);
await welcomeTester.findTitle();
await welcomeTester.scrollThePage();
await welcomeTester.tapButton(WelcomeKeys.btnHaveAccount);
await welcomeTester.checkScreenOpenedByKey(LoginKeys.screenLoginPage);
});
testWidgets('Test case 2',
(WidgetTester tester) async {
await tester.pumpAndSettle(const Duration(seconds: 5));
welcomeTester = WelcomeTester(tester);
await welcomeTester.checkScreenOpenedByKey(WelcomeKeys.screenWelcomePage);
await welcomeTester.tapButton(WelcomeKeys.btnCreateAccount);
await welcomeTester.checkScreenOpenedByKey(OnboardingKeys.screenTermsPage);
});
});
}
My goal is to create in app_test.dart several test groups and in each group several TestWidgets
You need to use this everytime the app changes to give it a chance to move onto the next action.
To settle to UI before moving onto the next action.
Docs: https://api.flutter.dev/flutter/flutter_test/WidgetTester/pumpAndSettle.html