function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sudip Mondal 2001Sudip Mondal 2001 

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.
Best Answer chosen by Sudip Mondal 2001
srlawr uksrlawr uk
yes, not only do you need 75% coverage, all test methods must pass as well...

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

srlawr uksrlawr uk
yes, not only do you need 75% coverage, all test methods must pass as well...

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!


 
This was selected as the best answer
Sudip Mondal 2001Sudip Mondal 2001
Hey srlawr uk,

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
srlawr uksrlawr uk
Sounds like a very reasonable solution. Glad you were able to get the test passing! :)