Search code examples
javajunitjunit4

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.


Solution

  • 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.