runTest method

  1. @override
Future<void> runTest (
  1. Future<void> testBody(
      ),
    1. VoidCallback invariantTester,
    2. {String description: '',
    3. Duration timeout}
    )
    override

    Call the testBody inside a FakeAsync scope on which pump can advance time.

    Returns a future which completes when the test has run.

    Called by the testWidgets and benchmarkWidgets functions to run a test.

    The invariantTester argument is called after the testBody's Future completes. If it throws, then the test is marked as failed.

    The description is used by the LiveTestWidgetsFlutterBinding to show a label on the screen during the test. The description comes from the value passed to testWidgets. It must not be null.

    The timeout argument sets the initial timeout, if any. It can be increased with addTime. By default there is no timeout.

    Implementation

    @override
    Future<void> runTest(
      Future<void> testBody(),
      VoidCallback invariantTester, {
      String description = '',
      Duration timeout,
    }) async {
      // TODO(jackson): Report the results individually instead of all at once
      // See https://github.com/flutter/flutter/issues/38985
      final TestExceptionReporter oldTestExceptionReporter = reportTestException;
      reportTestException =
          (FlutterErrorDetails details, String testDescription) {
        _results[description] = 'failed';
        _failureMethodsDetails.add(Failure(testDescription, details.toString()));
        if (!_allTestsPassed.isCompleted) {
          _allTestsPassed.complete(false);
        }
        oldTestExceptionReporter(details, testDescription);
      };
      await super.runTest(
        testBody,
        invariantTester,
        description: description,
        timeout: timeout,
      );
      _results[description] ??= 'success';
    }