JUnit 5: How to assert an exception is thrown?

Is there a better way to assert that a method throws an exception in JUnit 5?

Currently, I have to use an @Rule in order to verify that my test throws an exception, but this doesn’t work for the cases where I expect multiple methods to throw exceptions in my test.

10 Answers
10

Leave a Comment