Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Junit - Interview Questions and Answers for 'Junit exception testing' - 1 question(s) found - Order By Newest | ||||
| ||||
Ans. Yes, We can pass the test even if the tested method throws an exception. One way is know as exception testing in which the tested method is expected to throw exception and hence the expectation is set accordingly. @Test(expected = IndexOutOfBoundsException.class) public void test(){} Other way is to just ignore if the tested code throws an exception. In that case , we can enclose the tested method call in the try block and within exception block, we just return gracefully. Exception testing is perfectly ok to be done as we would like test code in case an exception occurs and if the code is handling the exception properly. Ignoring the exception by putting the tested method call within try block isn't something normal and should be avoided. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Junit exception testing | ||||
Related Questions | ||||