parametizedTest<T> function

void parametizedTest<T>(
  1. List<T> args,
  2. Function testFn
)

Creates a collection of test calls based on the given test parameters, where each element in the args list will be passed to a test function as a separate test run.

The test calls generated with this function are NOT wrapped in a group call.

Arguments

  • List<T> args - the list of arguments for each test run.
  • Function testFn - the test function to be executed.

Example

The example below would add the first two numbers in each argument element and expect the result to be the third element.

group('testing addition', (){
  parametizedTest<List<int>>(
    [
      [1, 2, 3],
      [2, 4, 6],
    ],
    (List<int> arg) => expect(arg[0] + arg[1], equals(arg[2])),
  );
});

Implementation

void parametizedTest<T>(List<T> args, Function testFn) {
  for (final arg in args) {
    test(' - testing: $arg', () {
      // ignore: avoid_dynamic_calls
      testFn(arg);
    });
  }
}