Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore the exception in flutter integration test & continue the test execution

I'm getting FirebaseException is CAUGHT BY FLUTTER TEST FRAMEWORK, while flutter integration test is being run.!

Can anybody help in understading how to ignore the FirebaseException in integration test and continue the rest of execution?

I tried below walkaround,

Future<void> restoreFlutterError(Future<void> Function() call) async {
  FlutterError.onError = (FlutterErrorDetails data) {
    if (data.exception is FirebaseException) {
      return;
    }
    FlutterError.presentError(data);
  };
}

And called above method in testWidgets by

testWidgets('test execution', (tester) async {
    await restoreFlutterError(() async {
      app.main();
      await tester.pumpAndSettle(const Duration(seconds: 10));
    });
    ...
    ...
});

But getting below error.!

 A test overrode FlutterError.onError but either failed to return it to its original state, or had unexpected additional errors that it could not handle. Typically, this is caused by using expect() before restoring FlutterError.onError.

Any helps appreciated.!

like image 564
Jagadeesh Avatar asked Nov 03 '25 07:11

Jagadeesh


1 Answers

I managed to ignore exceptions by modifying FlutterError.onError function. Something like this worked for me:

 Future<void> ignoreException(Type exceptionType) async {
   final originalOnError = FlutterError.onError!;
  FlutterError.onError = (FlutterErrorDetails details) {
    final currentError = details.exception.runtimeType;
    if (currentError == exceptionType) {
      return;
    }
    originalOnError(details);
  };
}

Later calling it in testWidgets like this, depending on the Exception thrown that you want to ignore:

await ignoreException(NetworkImageLoadException);
like image 135
Kule Avatar answered Nov 04 '25 20:11

Kule



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!