test method

void test({
  1. String? testDescription,
  2. String? featureDescription,
  3. int? nrScenario,
  4. int? nrFeature,
  5. UnitMocks? mocks,
  6. SUT? systemUnderTest,
})

Runs all tests defined in this UnitScenarios _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({
  String? testDescription,
  String? featureDescription,
  int? nrScenario,
  int? nrFeature,
  UnitMocks? mocks,
  SUT? systemUnderTest,
}) {
  assert((_systemUnderTestCallback != null) || (systemUnderTest != null),
      'You must specify a systemUnderTest in a UnitScenario or higher up the tree.');
  flutter_test.group(
    _description,
    () {
      final _mocks = mocks ?? UnitMocks();
      _setUpMocks?.call(_mocks);
      final SUT _systemUnderTest =
          _systemUnderTestCallback?.call(_mocks) ?? systemUnderTest!;
      _setUpAndTeardown(mocks: _mocks, systemUnderTest: _systemUnderTest);
      for (int index = 0; index < math.max(1, _examples.length); index++) {
        flutter_test.test(
          _examples.isNotEmpty
              ? 'Example ${index + 1}: ${_examples[index]}'
              : _description,
          () async {
            debugPrintSynchronously('---');
            try {
              if (testDescription != null) {
                debugPrintSynchronously(
                    '${UnitLog.tag} 📝 Test: $testDescription');
              }
              if (featureDescription != null) {
                debugPrintSynchronously(
                    '${UnitLog.tag} 🦾 Feature${nrFeature != null ? ' ${nrFeature + 1}' : ''}: $featureDescription');
              }
              debugPrintSynchronously(
                  '${UnitLog.tag} 🎩 Scenario${nrScenario != null ? ' ${nrScenario + 1}' : ''}: $_description');
              if (_examples.isNotEmpty) {
                final example = _examples[index];
                debugPrintSynchronously(
                    '${UnitLog.tag} 🏷 Example ${index + 1}: $example');
              }
              debugPrintSynchronously('${UnitLog.tag} 🎬 --- Test started!');
              final box = UnitBox();
              for (final step in _steps) {
                if (_examples.isNotEmpty) {
                  await step.test(
                    systemUnderTest: _systemUnderTest!,
                    log: _log,
                    example: _examples[index],
                    box: box,
                    mocks: _mocks,
                  );
                } else {
                  await step.test(
                    log: _log,
                    systemUnderTest: _systemUnderTest!,
                    box: box,
                    mocks: _mocks,
                  );
                }
              }
            } catch (error) {
              debugPrintSynchronously('${UnitLog.tag} ❌ Test failed!\n---');
              rethrow;
            }
          },
        );
      }
    },
  );
}