Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run multiple tests with flutter - Integration Test

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

like image 987
Tiago Felipe Dias de Oliveira Avatar asked Feb 16 '26 08:02

Tiago Felipe Dias de Oliveira


1 Answers

You need to use this everytime the app changes to give it a chance to move onto the next action.

      await tester.pumpAndSettle();

To settle to UI before moving onto the next action.

Docs: https://api.flutter.dev/flutter/flutter_test/WidgetTester/pumpAndSettle.html

like image 159
Gerry Avatar answered Feb 19 '26 12:02

Gerry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!