tester method
run test
providing a description
and an example
function
Implementation
void tester({
required String name,
required NullaryAsync<T> example,
}) {
group('test for $name', () {
final tester = Stub.nullary<Future<T>>();
setUp(tester.reset);
test(
'GIVEN $name original function does not throw '
'WHEN $name.call '
'THEN return Success', () {
tester.stub = example;
expectLater(
tester(),
isA<Result<T>>(),
reason: 'tester should not throw',
);
});
test(
'GIVEN $name original function throws Exception '
'WHEN $name.call '
'THEN return Failure', () {
tester.stub = () => throw Exception();
expect(
tester(),
isA<Failure<T>>(),
reason: 'tester should throw',
);
});
test(
'GIVEN $name original function throws Error '
'WHEN $name.call '
'THEN return Failure', () {
tester.stub = () => throw Error();
expect(
tester(),
isA<Failure<T>>(),
reason: 'tester should throw',
);
});
});
}