fail() method
This lesson demonstrates the importance of the fail method in JUnit 5 Assertions API.
We'll cover the following
fail() method
Assertions API provide static fail()
method. As soon as, any @Test
method encounters fail()
static method, it will fail the test case. The primary usages of fail()
method are as follows -
- It gives a piece of meaningful information to the programmer writing a test, that test case is in progress and still needs to be implemented.
- It can be used to verify that an actual exception is thrown. Usually based on some input when test case expects an exception at a certain line, providing
fail()
below that line will verify that exception was not thrown as code execution reachedfail()
method line. Thus, it explicitly fails the test case.
There are basically five useful overloaded methods to fail:-
Get hands-on with 1400+ tech skills courses.