test method

void test({
  1. IntegrationTestWidgetsFlutterBinding? binding,
  2. String? testDescription,
  3. String? featureDescription,
  4. int? nrScenario,
  5. int? nrFeature,
  6. IntegrationMocks? mocks,
})

Runs all tests defined in this IntegrationScenarios _steps.

All tests run at least once (or more depending on the amount of examples) and inside their own testWidgets method. Override this method and call your _steps test() methods in a different manner if this unwanted behaviour.

Implementation

void test({
  IntegrationTestWidgetsFlutterBinding? binding,
  String? testDescription,
  String? featureDescription,
  int? nrScenario,
  int? nrFeature,
  IntegrationMocks? mocks,
}) {
  flutter_test.group(
    _description,
    () {
      final _mocks = mocks ?? IntegrationMocks();
      _setUpMocks?.call(_mocks);
      _setUpAndTeardown(mocks: _mocks);
      for (int index = 0; index < math.max(1, _examples.length); index++) {
        flutter_test.testWidgets(
          _examples.isNotEmpty
              ? 'Example ${index + 1}: ${_examples[index]}'
              : _description,
          (tester) async {
            debugPrintSynchronously('---');
            try {
              if (testDescription != null) {
                debugPrintSynchronously(
                    '${IntegrationLog.tag} 📝 Test: $testDescription');
              }
              if (featureDescription != null) {
                debugPrintSynchronously(
                    '${IntegrationLog.tag} 🦾 Feature${nrFeature != null ? ' ${nrFeature + 1}' : ''}: $featureDescription');
              }
              debugPrintSynchronously(
                  '${IntegrationLog.tag} 🎩 Scenario${nrScenario != null ? ' ${nrScenario + 1}' : ''}: $_description');
              if (_examples.isNotEmpty) {
                final example = _examples[index];
                debugPrintSynchronously(
                    '${IntegrationLog.tag} 🏷 Example ${index + 1}: $example');
              }
              debugPrintSynchronously(
                  '${IntegrationLog.tag} 🎬 Test started!');
              final box = IntegrationBox();
              for (final step in _steps) {
                if (_examples.isNotEmpty) {
                  await step.test(
                    tester: tester,
                    log: _log,
                    example: _examples[index],
                    binding: _binding ?? binding,
                    box: box,
                    mocks: _mocks,
                  );
                } else {
                  await step.test(
                    tester: tester,
                    binding: binding,
                    box: box,
                    log: _log,
                    mocks: _mocks,
                  );
                }
              }
            } catch (error) {
              debugPrintSynchronously(
                  '${IntegrationLog.tag} ❌ Test failed!\n---');
              rethrow;
            }
          },
        );
      }
    },
  );
}