testDataCasesUnder function

void testDataCasesUnder(
  1. {required Symbol library,
  2. String subdirectory = '',
  3. String extension = 'unit',
  4. bool recursive = true,
  5. required void testBody(
    1. DataCase dataCase
    )}
)

Declare a test for each data case found in the directory containing library, using testBody as the test body, with each data case passed to testBody.

directory, extension, and recursive all act the same as in dataCases.

The test's description will be generated from the directory, file, and description of the data case.

A test will be skipped if it's description starts with "skip:".

Example:

library my_package.test.this_test;

import 'package:expected_output/expected_output.dart';
import 'package:test/test.dart';

void main() {
  testDataCasesUnder(library: #my_package.test.this_test,
      testBody: (DataCase dataCase) {
    var output = myFunction(dataCase.input);
    expect(dataCase.expectedOutput, equals(output));
  });
}

Implementation

void testDataCasesUnder(
    {required Symbol library,
    String subdirectory = '',
    String extension = 'unit',
    bool recursive = true,
    required void Function(DataCase dataCase) testBody}) {
  for (var dataCase in dataCasesUnder(
      library: library,
      subdirectory: subdirectory,
      extension: extension,
      recursive: recursive)) {
    test(dataCase.description, () => testBody(dataCase), skip: dataCase.skip);
  }
}