In swift-test vision document the author explained the rational behind simple expectation API decision. That makes sense to me but I find it inconvenient without a built-in API to test error. Below is an example.
Setup: I'd like to test func foo() throws an expected error.
I wonder if there is better way to do it? While the code is simple, copying and pasting it in every test seems unacceptable. I'm thinking to move them to a function. But if every user defines a custom function like this, doesn't it mean the library should provide one out-of-box? Am I missing something? Thanks.
Either call the throwing function directly—and if an error is thrown, allow the test to fail—or, if you want to emphasize the semantics of the function not throwing, use Never with #expect(throws:):