You need to sign in to do that
Don't have an account?
Return statement not covered in test method
I have written a test method for webservice method. Here i am facing code coverage problem.
The below image covered till the line of 'insert u' but i am not sure why it hasn't cover the line of return statement. Here no issues in Insert statement. The test method was passed successfully.
public static ID createuser('testuser','lastname')
{
---------------....
...........................
insert u; // Covered till this line
return u.id; //this line not covered
}
The above method not works at return statement so that method declaration place also not covered.
My question is why the return statement is not covered even no issues in test method. Anybody pls help.
Based on my experience, it sounds like the insert u dml statement failed, but a try-catch block further up the execution stack caught the error (thus causing the test method to still pass). Trace your code through its execution stack and make sure you're handling the error as you intended.
All Answers
Based on my experience, it sounds like the insert u dml statement failed, but a try-catch block further up the execution stack caught the error (thus causing the test method to still pass). Trace your code through its execution stack and make sure you're handling the error as you intended.
Thanks for your help,
I resolved this. I removed the try, catch statement from my class and again run the test method, it throws the error to my hand catch.