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
sales4cesales4ce 

Test Method-Code coverage average is above 75% but not while testing Individually

Hi,

 

I have a trigger that needs to be deployed to production.

I have written test method to get a code coverage of above 75%. This works fine when i do "Run All Test Cases", but not individually.

When i run my test class individually i get 68% coverage, while the  average of all test cases is 96%.

 

My issue is i need to push only individual trigger but not all triggers and classes?

does it allow me to deploy?can any body let me know how this could be achieved or am i doing anything wrong?

 

Thanks,

Sales4ce

 

 

frederic baudaxfrederic baudax

Hi,

 

I see 2 options, either re-deploye all test classes with your trigger or re-work the related test class to cover your trigger for at least 75%

 

The reason you get such a high coverage with run all test but not individually is because your trigger gets covered with one or more other test classes, maybe even partially in several classes but only 68% with that one class .

 

Kr,

Fred

Pradeep_NavatarPradeep_Navatar

It is not possible to deploy any trigger or class which has a coverage below 75%.

 

It will allow you to upload only if the cumulative test coverage of all the classes is above 75%. You need to deploy it with all the other classes or increase the test coverage of the class and try deploying again.

 

Hope this helps.

sales4cesales4ce

Thanks for your replies!

 

Assume that i have 3 triggers on Lead Object.They had their test coverage and have been deployed to production.

Now i have developed another trigger(4th) on Lead Object and i have developed a separate test class for this trigger.

 

Now, when i write test coverage for 4th one, it will also invoke other triggers. right?

Since i did not have them covered in my test class , the cumulative test coverage would go below 75%.

 

So what would be a best practice here in these situations?. Should i go ahead and write my test coverage to already written test class?

 

Thanks,

Sales4ce

Ispita_NavatarIspita_Navatar

How are you deploying your  triggers?Say in case you are using ecllipse and you want to deploy just your fourth trigger, then your test class needs to cover only the 4th trigger. As you do a "Run test" check if the 4th trigger has  adequate coverage -75% or above, if yes then in ecllipse select just your trigger and deploy it should go through as the trigger you want to deploy has adequate coverage.

In case you have further doubts do ask.

sales4cesales4ce

Thanks for reply!

 

I have another question.suppose i have a trigger on Lead object that should fire only when users who share a custom profile.

 

trigger add_task on Lead( before Insert)

{

    if(user.getprofileId()='00p0000000aN6T')

   {

        //do custom functionality

    }

}

 

Now, how would i write a test case for this scenario, since the profile ID would be unique to organization.What  i mean is when i try to deploy, the profile ID would chnage in production org. How should i handle this?

 

Any idea on this is highly appreciated.

 

Thanks,

Kumar

frederic baudaxfrederic baudax

Hi,

 

If the profile has been created before your last sandbox copy then the profile Id is the same in both, simply compare sandbox and production to be sure. As for the test method, you will have to use a  System.runAs() if you have a different profile that the one required to fire the trigger.

 

Kr,

Fred

Pradeep_NavatarPradeep_Navatar

Please create a new thread for a new question.