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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -