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

Test method coverage for Exceptions
Hi,
I am handling exception using try-catch but at the time of writing test class fail to cover catch block part,
this happens at the time when I am inserting any object.
For example,
try{
.........
insert contact;
}
catch(Exception e) // fail to cover this part of code
{..........}
Can anybody help me to solve this problem.
Thanks,
Pratty
Hi,
If the Type of Exception in Catch is "Exceltion" class then simply in your test code :
Assign the ID to object you are trying to insert.
It will give you error that object cannot have ID suring insert and your control will come into catch block.
I hope this will help you.