Skip to content

Latest commit

History

History
39 lines (21 loc) 路 1.23 KB

File metadata and controls

39 lines (21 loc) 路 1.23 KB

Testing functions that throw

When writing test expectations for functions that throw, we need a bit careful.

If we call the function directly, the test will fail as it won't catch the exception as we expect.

In these cases, we should always pass a closure when calling the expect method as shown here. 馃憞


Here's a comparison I made to explain why calling the method directly won't work.

These two implementations are equivalent. And they both fail because the function will execute and throw before expect() is even called. 馃憞


Hope this will save you some headaches. 馃憤

For more Flutter tweets like this, follow me: @biz84

Happy coding!


Found this useful? Show some love and share the original tweet 馃檹

Also published on codewithandrea.com 馃憞


Previous Next
Why write automated tests? Dart 2.17: Super Initializers