integrationDriver function Null safety

Future<void> integrationDriver(
  1. {Duration timeout = const Duration(minutes: 20),
  2. ResponseDataCallback? responseDataCallback = writeResponseData}
)

Adaptor to run an integration test using flutter drive.

To an integration test <test_name>.dart using flutter drive, put a file named <test_name>_test.dart in the app's test_driver directory:

import 'dart:async';

import 'package:integration_test/integration_test_driver.dart';

Future<void> main() async => integrationDriver();

Parameters:

timeout controls the longest time waited before the test ends. It is not necessarily the execution time for the test app: the test may finish sooner than the timeout.

responseDataCallback is the handler for processing Response.data. The default value is writeResponseData.

onScreenshot can be used to process the screenshots taken during the test. An example could be that this callback compares the byte array against a baseline image, and it returns true if both images are equal.

As a result, returning false from onScreenshot will make the test fail.

Implementation

Future<void> integrationDriver({
  Duration timeout = const Duration(minutes: 20),
  ResponseDataCallback? responseDataCallback = writeResponseData,
}) async {
  final FlutterDriver driver = await FlutterDriver.connect();
  final String jsonResult = await driver.requestData(null, timeout: timeout);
  final Response response = Response.fromJson(jsonResult);

  await driver.close();

  if (response.allTestsPassed) {
    print('All tests passed.');
    if (responseDataCallback != null) {
      await responseDataCallback(response.data);
    }
    exit(0);
  } else {
    print('Failure Details:\n${response.formattedFailureDetails}');
    exit(1);
  }
}