I would like to run a Dart test which is repeated with a set of inputs and expected outputs, similar to what is possible with JUnit.
I wrote the following test to achieve similar behavior but the problem is that event if all the test outputs are computed incorrectly, the test will only fail once:
import 'package:test/test.dart';
void main() {
test('formatDay should format dates correctly', () async {
var inputsToExpected = {
DateTime(2018, 11, 01): "Thu 1",
...
DateTime(2018, 11, 07): "Wed 7",
DateTime(2018, 11, 30): "Fri 30",
};
// When
var inputsToResults = inputsToExpected.map((input, expected) =>
MapEntry(input, formatDay(input))
);
// Then
inputsToExpected.forEach((input, expected) {
expect(inputsToResults[input], equals(expected));
});
});
}
The reason I want to use parameterized tests, is so that I can achieve the following behavior in my test:
- Write only one test
- Test
ndifferent inputs/outputs - Fail
ntimes if allntests are broken