Skip to content

Instantly share code, notes, and snippets.

@magillus
Last active March 21, 2019 22:05
Show Gist options
  • Save magillus/62e7107e6bdcbe996ed976837dc95fc8 to your computer and use it in GitHub Desktop.
Save magillus/62e7107e6bdcbe996ed976837dc95fc8 to your computer and use it in GitHub Desktop.
Dart Unit tests - expectException method.
import 'package:test/test.dart';
main() {
test("throw excpetion test",() {
expectException(()=>throw Exception("sample error"), Exception);
});
}
typedef void Runner();
void expectException(Runner runner, type) {
var thrownException;
try {
runner();
} catch (e) {
thrownException = e;
}
expect(thrownException?.runtimeType, type,
reason: "Expecting Exception of type: $type");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment