Last active
March 21, 2019 22:05
-
-
Save magillus/62e7107e6bdcbe996ed976837dc95fc8 to your computer and use it in GitHub Desktop.
Dart Unit tests - expectException method.
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: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