Skip to content
Advertisement

How to make a Junit test case fail if there is any exception in the code?

I wrote a Junit test to unit test my code. I want my Junit test case to fail when I get any exception in my code. I tried using an assert statement, but even when I get an exception in my code, my Junit test case is passing. Please can anyone tell me how I can achieve this? Thanks.

Advertisement

Answer

You can assert that a global variable “excepted” = null or something like that and initialize it to equal some information string in the catch block.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement