runOne method

Future<EnsembleTestRunOutput> runOne(
  1. EnsembleTestCase test,
  2. WidgetTester tester, {
  3. EnsembleConfig? existingConfig,
  4. bool continuation = false,
})

Runs a single test, optionally continuing an existing app session.

Implementation

Future<EnsembleTestRunOutput> runOne(
  EnsembleTestCase test,
  WidgetTester tester, {
  EnsembleConfig? existingConfig,
  bool continuation = false,
}) async {
  final stopwatch = Stopwatch()..start();

  try {
    final ctx = EnsembleTestContext.fromTestCase(test);
    TestErrorTracker.install(ctx.runtime);

    late final EnsembleConfig config;
    if (continuation) {
      if (!YamlTestSession.runtimeBootstrapped) {
        throw EnsembleTestFailure(
          'Test "${test.id}" has prerequisite "${test.prerequisite}" but the '
          'runtime is not bootstrapped — ensure the prerequisite test runs first',
        );
      }
      EnsembleTestHarness.applyInPlaceSetup(ctx);
      config = existingConfig ?? Ensemble().getConfig()!;
      await EnsembleTestHarness.waitForInitialWidgets(tester, testCase: test);
    } else {
      config = await harness.loadScreen(
        tester: tester,
        testCase: test,
        existingConfig: existingConfig,
        context: ctx,
      );
    }

    final result = await _executeSteps(
      test: test,
      tester: tester,
      ctx: ctx,
      config: config,
      stopwatch: stopwatch,
    );
    return (result: result, config: config);
  } catch (error, stackTrace) {
    final config = existingConfig ?? Ensemble().getConfig();
    return (
      result: EnsembleSingleTestResult.failed(
        testId: test.id,
        metadata: test.metadataJson,
        error: error.toString(),
        stackTrace: stackTrace.toString(),
        durationMs: stopwatch.elapsedMilliseconds,
        report: buildTestReportDetails(test),
      ),
      config: config ?? await harness.buildConfig(),
    );
  } finally {
    TestErrorTracker.reset();
  }
}