IntegrationTestWidgetsFlutterBinding constructor

IntegrationTestWidgetsFlutterBinding()

Sets up a listener to report that the tests are finished when everything is torn down.

Implementation

IntegrationTestWidgetsFlutterBinding() {
  tearDownAll(() async {
    if (!_allTestsPassed.isCompleted) {
      _allTestsPassed.complete(failureMethodsDetails.isEmpty);
    }
    callbackManager.cleanup();

    // TODO(jiahaog): Print the message directing users to run with
    // `flutter test` when Web is supported.
    if (!_shouldReportResultsToNative || kIsWeb) {
      return;
    }

    try {
      await integrationTestChannel.invokeMethod<void>(
        'allTestsFinished',
        <String, dynamic>{
          'results': results.map<String, dynamic>((String name, Object result) {
            if (result is Failure) {
              return MapEntry<String, dynamic>(name, result.details);
            }
            return MapEntry<String, Object>(name, result);
          }),
        },
      );
    } on MissingPluginException {
      debugPrint(r'''
Warning: integration_test plugin was not detected.

If you're running the tests with `flutter drive`, please make sure your tests
are in the `integration_test/` directory of your package and use
`flutter test $path_to_test` to run it instead.

If you're running the tests with Android instrumentation or XCTest, this means
that you are not capturing test results properly! See the following link for
how to set up the integration_test plugin:

https://flutter.dev/docs/testing/integration-tests#testing-on-firebase-test-lab
''');
    }
  });

  final TestExceptionReporter oldTestExceptionReporter = reportTestException;
  reportTestException =
      (FlutterErrorDetails details, String testDescription) {
    results[testDescription] = Failure(testDescription, details.toString());
    oldTestExceptionReporter(details, testDescription);
  };
}