You need to sign in to do that
Don't have an account?

testing code in catch block
How can the code in catch block be covered under test ?
public void someMethod()
{
try
{
some code...
}
catch(Exception e)
{
some code - how to get test coverage for this code ?
throw e;
}
}
Thanks in advance!
Hi,
Lets assume that you have a method to update a Account record.
I am giving a snippet of code to cover try/catch block inside test method.
To cover a catch block, you need identify the situation when your code invoke the catch block.
For example, the situation where object instance is not found. Therefore in the test method, I have deleted the account instance that i created and once again invoke the save method.
Hope this helps :)
Thanks,
Devendra