Last active
April 27, 2024 16:24
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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