execute method

Future<void> execute(
  1. TestConfiguration config
)

Implementation

Future<void> execute(TestConfiguration config) async {
  config.prepare();
  _registerReporters(config.reporters);
  _registerHooks(config.hooks);
  _registerCustomParameters(config.customStepParameterDefinitions);
  _registerStepDefinitions(config.stepDefinitions);
  _languageService.initialise(config.featureDefaultLanguage);

  var featureFiles = await _getFeatureFiles(config);

  var allFeaturesPassed = true;

  if (config.order == ExecutionOrder.random) {
    await _reporter.message(
      'Executing features in random order',
      MessageLevel.info,
    );
    featureFiles = featureFiles.toList()..shuffle();
  } else if (config.order == ExecutionOrder.alphabetical) {
    await _reporter.message(
      'Executing features in sorted order',
      MessageLevel.info,
    );
    featureFiles.sort(
      (FeatureFile a, FeatureFile b) => a.name.compareTo(b.name),
    );
  }

  await _hook.onBeforeRun(config);

  try {
    await _reporter.onTestRunStarted();
    for (var featureFile in featureFiles) {
      final runner = FeatureFileRunner(
        config,
        _tagExpressionEvaluator,
        _executableSteps,
        _reporter,
        _hook,
      );
      allFeaturesPassed &= await runner.run(featureFile);
      if (config.stopAfterTestFailed && !allFeaturesPassed) {
        break;
      }
    }
  } finally {
    await _reporter.onTestRunFinished();
    await _hook.onAfterRun(config);
    await _reporter.dispose();

    if (!allFeaturesPassed) {
      throw GherkinTestRunFailedException();
    }
  }
}