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

Test Class coverage details
Hi Team,
I need your help in getting a doubt clearified.
I have got to write a test class for trigger and the corresponding handler class. I have written the test class and the test coverage is 100% - trigger and 89% - Handler class.
But when I am runnign the test class, its failing. Saying 1/2 methods passed. I had to cover negetive scenario aswell because it was a catch portion which I needed to cover thus created a knowing error in the negetive test method.
Kindly lemme know if passing of the test classes is as important as covering the classes and triggers for successful deployment? In other words, I need atleast 75% coverage and a passes test clas for successful deployment.
I need your help in getting a doubt clearified.
I have got to write a test class for trigger and the corresponding handler class. I have written the test class and the test coverage is 100% - trigger and 89% - Handler class.
But when I am runnign the test class, its failing. Saying 1/2 methods passed. I had to cover negetive scenario aswell because it was a catch portion which I needed to cover thus created a knowing error in the negetive test method.
Kindly lemme know if passing of the test classes is as important as covering the classes and triggers for successful deployment? In other words, I need atleast 75% coverage and a passes test clas for successful deployment.
Sounds like what you need to do is either better error handling in your code (so it doesn't kick out and fail) or in your negative test, you need to catch the appropriate error and deal with in (and then assert that you caught it and dealt with it)
- which of those approaches you adopt will depend on how your actual functionality needs to handle the problem.. either swallow it up and manage the data appropriatly, or throw an error message back up to the user.
Either way, yes all tests must pass!
All Answers
Sounds like what you need to do is either better error handling in your code (so it doesn't kick out and fail) or in your negative test, you need to catch the appropriate error and deal with in (and then assert that you caught it and dealt with it)
- which of those approaches you adopt will depend on how your actual functionality needs to handle the problem.. either swallow it up and manage the data appropriatly, or throw an error message back up to the user.
Either way, yes all tests must pass!
Thanks a lot for clarifying this. I simply covered the portion throwing error within a try-catch block and the error was handled. So, this is where I stand now:
Test class passed? Yes
Code coverage above 75% ? Yes 89% and 100% respectively.
Thank you again for your answer.. :)
Regards,
Sudip