For example, if I have something like this:
try {
// db call
} catch ( Exception e ) {
return false
}
I want to write a unit test to test this method. How should I write that? Or to say it differently, what will be an example of code that will cause SQLException or any other exception to be thrown?
We usually write such a test code like this:
The Assert.fail() part makes sure that the test fails in case the code did not throw the error.