How to test a function which throws exception, in Dart?

dart, unit-testing

Solution

You can pass `hello` directly by name instead of creating a closure that only calls `hello`.

This unit-test passes:

main() {
  test("function hello should throw exception", () {
      expect(hello, throwsA(new isInstanceOf<String>()));
  });
}

Problem

Say I have a function which throws exception: ``` hello() { throw "exception of world"; } ``` I want to test it, so I write a test: ``` test("function hello should throw exception", () { expect(()=>hello(), throwsA("exception of world")); }); ``` You can see I didn't call `hello()` directly, instead, I use `()=>hello()`. It works but I wonder if is there any other way to write tests for it?

Original source