unit testing - How to test a function which throws exception, in Dart? -
say have function throws exception:
hello() { throw "exception of world"; }
i want test it, write test:
test("function hello should throw exception", () { expect(()=>hello(), throwsa("exception of world")); });
you can see didn't call hello()
directly, instead, use ()=>hello()
.
it works wonder if there other way write tests it?
you can pass hello
directly name instead of creating closure calls hello
.
this unit-test passes:
main() { test("function hello should throw exception", () { expect(hello, throwsa(new isinstanceof<string>())); }); }
Comments
Post a Comment