Skip to content

Instantly share code, notes, and snippets.

@ikoamu
Last active April 27, 2024 16:24
Show Gist options
  • Save ikoamu/a2b3426b55bd9ac943ff3cefb09b2152 to your computer and use it in GitHub Desktop.
Save ikoamu/a2b3426b55bd9ac943ff3cefb09b2152 to your computer and use it in GitHub Desktop.
A util function that can do a Parameterized Test with Dart like `each` in Jest.
import 'package:meta/meta.dart';
@isTestGroup
void Function(void Function(T param) test) each<T>(
String description, List<T> params) =>
(Function(T) test) => group(description, () => params.forEach(test));
void example() {
each("multiply", [
(a: 0, b: 0, expected: 0),
(a: 1, b: 1, expected: 1),
(a: 2, b: 2, expected: 4),
(a: 3, b: 3, expected: 9),
])((param) {
test('${param.a} * ${param.b} = ${param.expected}', () {
expect(multiply(param.a, param.b), param.expected);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment