Assertions: assertThrows() and assertThrowsExactly()
Let's learn assertThrows() and assertThrowsExactly() assertions in JUnit 5.
The assertThrows() method
The assertThrows() method asserts that the execution of the given Executable throws an exception of the expectedType. The thrown exception is returned for further assertions.
- If the
expectedTypeisExceptionand the actual isRuntimeException, the assertion passes. - If no exception is thrown, or if
Ask