Selasa, 27 Juli 2021

How to test Exception thrown by a Java Method in JUnit? Example

One part of unit testing a Java method is checking exceptions thrown by that method. A Java unit test should verify the correct exception thrown in the exceptional case and no exception should be thrown in a normal case. In JUnit 3.XX, there was no direct support to pass or fail a test based upon the exception thrown by a Java method. JUnit4 address this issue and provides an easy, and readable way to test exceptions thrown by a Java method. There are many situations when you need to test the exception thrown by any method in Java. A classical example of this is testing API methods which should throw IllegalArgumentException if arguments passed to the method are not matching to pre-conditions.

Lorem ipsum is simply dummy text of the printing and typesetting industry.

Comments


EmoticonEmoticon