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
sfdcFanBoysfdcFanBoy 

apex code coverage %

My overall apex code coverage is 86% in production (With around 35 apex classes and triggers).

 

Now when I am trying to deploy 3 new classes with the code coverages of (100, 88 and 9),  it is throwing the error.

 

Average test coverage across all Apex Classes and Triggers is 73%, at least 75% test coverage is required.

 

Why is the overall coverage dropping to such a low %.  How is it calculated?

 

Im struggling to increase the percentage for 9% covered apex class.  Is there any way to deploy it ?

 

Also, I have tried adding 2 dummy classes with test classes of both 100%, still it remains at 73% ! 

 

Any workaround?  Let me know.

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
Peter_sfdcPeter_sfdc

There is an excellent blog by Josh Kaplan the Apex product manager on code coverage and how it works. 

 

The percent used when deploying is a calculation across your entire org. It does seem a little startling that one class with very low code coverage could reduce your overall code coverage by that much, but if it is a very large class (lots of lines) it is possible. 

 

Why is code coverage for that class so low? It doesn't sound like you'd have to do much to get enough code coverage on that one class to improve your code coverage. 

 

Remember unit tests are there to help you, and salesforce.com makes use of them every release in the hammer test cycle where we execute every unit test against the code base of the new release. So in the end, writing a vew more unit tests, while seeming to be inconvenient in the immediate future, will only help you and salesforce.com in the long run. 

All Answers

Peter_sfdcPeter_sfdc

There is an excellent blog by Josh Kaplan the Apex product manager on code coverage and how it works. 

 

The percent used when deploying is a calculation across your entire org. It does seem a little startling that one class with very low code coverage could reduce your overall code coverage by that much, but if it is a very large class (lots of lines) it is possible. 

 

Why is code coverage for that class so low? It doesn't sound like you'd have to do much to get enough code coverage on that one class to improve your code coverage. 

 

Remember unit tests are there to help you, and salesforce.com makes use of them every release in the hammer test cycle where we execute every unit test against the code base of the new release. So in the end, writing a vew more unit tests, while seeming to be inconvenient in the immediate future, will only help you and salesforce.com in the long run. 

This was selected as the best answer
amilawamilaw

do you have a very large number of line in yous 9% class compared to other classes. if u can please put the the code of that class

sfdcFanBoysfdcFanBoy
Thanks for the reply.

Yes, this is big class with close to 900 lines of code.

I have issues writing test class to this because this is a batch apex class which makes webservice callouts.
amilawamilaw

this link might help you.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex_testing.htm

 

and try to use Test.IsRunningTest method to assign mock values as you web service result.

 

Yuo dont have other options than 75% overall code coverage

sandeep@Salesforcesandeep@Salesforce

Although your production code coverage is 86% but including classes in deployment over all code coverage should not more than 75% and it is not happening so classes your are deploying, needed to be more code coverage.