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

839 views Asked by At

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.!

1

There are 1 answers

0
Kule On

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);