run static method

Future<TestCaseMonitor> run(
  1. FutureOr<void> body()
)

Run body as a test case and return a TestCaseMonitor with the result.

The state will either State.passed, State.skipped, or State.failed, the test will no longer be running.

Note that a test can change state from State.passed to State.failed if the test surfaces an unawaited asynchronous error.

final monitor = await TestCaseMonitor.run(() {
  fail('oh no!');
});
assert(monitor.state == State.failed);
assert((monitor.errors.single.error as TestFailure).message == 'oh no!');

Implementation

static Future<TestCaseMonitor> run(FutureOr<void> Function() body) async {
  final monitor = TestCaseMonitor.start(body);
  await monitor.onDone;
  return monitor;
}