parameterizedTest function

  1. @isTestGroup
void parameterizedTest(
  1. Object description,
  2. ParameterizedSource parameters,
  3. void body(
    1. List values
    ), {
  4. String? testOn,
  5. Timeout? timeout,
  6. dynamic skip,
  7. dynamic tags,
  8. Map<String, dynamic>? onPlatform,
  9. int? retry,
})

Create a group of parameterized tests.

The group will iterate over the supplied parameters. The parameters are supplied through a ParameterizedSource. Each test will be executed with the next parameter which will receive the parameter in the body.

parameterized test also have the same options as group tests have. These options will be passed to the group function.

For example:

parameterizedTest(
    'Amount of letters',
    ParameterizedSource.csv([
      'kiwi, 4',
      'apple, 5',
      'banana, 6',
    ]),
    (List<dynamic> values) {
      final String input = values[0];
      final expected = values[1];

      final actual = input.length;

      expect(actual, expected);
    },
  );

Implementation

@isTestGroup
void parameterizedTest(
  Object description,
  ParameterizedSource parameters,
  void Function(List<dynamic> values) body, {
  String? testOn,
  Timeout? timeout,
  dynamic skip,
  dynamic tags,
  Map<String, dynamic>? onPlatform,
  int? retry,
}) {
  group(description, () {
    for (final parameter in parameters.params) {
      test(
        parameter,
        () => body(parameter),
        testOn: testOn,
        timeout: timeout,
        skip: skip,
        tags: tags,
        onPlatform: onPlatform,
        retry: retry,
      );
    }
  });
}