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
Bill McBill Mc 

Inconsistent Code Coverage results

Hello everyone.  I have come upon an issue which is prohibiting our deployment of new components (even non-code items like templates) .

When we attempt to deploy a new changeset to production (even one without new APEX code) the system runs though our test cases as expected.  However, it replies with an error stating our code coverage is at 54% and thus cannot execute the deployment.  

However, when I run ALL Tests via the Developer Console and then use the Tooling API to retrieve the system wide code coverage (SELECT PercentCovered
FROM ApexOrgWideCoverage) it states 85%.  This apears correct to me when inspecting the coverage percentage by class and computing the total percentage.

My question is: Has anyone else encountered this issue and if so can they offer any advice as to how to resolve it?  

I have asked Salesforce for support by theu referred me here.

Kind regards, 

Bill McLaughlin
bob_buzzardbob_buzzard
I've found that the developer console reports the test coverage only for those classes that have tests, so if there are classes in production which have no coverage at all, the developer console ignores those and reports a higher level of coverage than is actually the case.  I hit this yesterday with a managed package - the developer console showed test coverage of 83%, but when I uploaded the package it was actually 72% and the upload failed.

I tend to use the Force.com IDE to get the real picture - it takes longer but I've found its more accurate.
Sagar PareekSagar Pareek
Hi Bill,

Use Force.com IDE, that will give you consistent code coverage result.

Bill McBill Mc
Hi bob_buzzard

Many thanks for your reply.  I can understand that ignored classes would lower the coverage total.  Is there a way to find out which classes have no tests?

Also, I am familiar with the Force.com IDE but cannot see how to run all tests. (I think I can see how to run an individual one by right-clicking on it and selecting Force.com--> Run test.  But even doing that appears to run all tests.)

What is the best method for running all tests and how do I get the total code coverege result when they are completed?

Your help is very much appreciated.

Bill
bob_buzzardbob_buzzard
You run all test by right clicking the classes folder and choosing 'Force.com -> Run Tests' from the context menu. This will execute all tests and show you test coverage across all classes in the results.
Bill McBill Mc
I have successfully run all tests now thank you. The Test results show a mix of 22 classes and 14 triggers with their coverage percentrage.

Do I now need to copy each of these these values and calculate a percentage myself?

Also, I have a total of 38 APEX classes.  Is there a way to identify which havent been tested other than manually comparing them?

Many thanks,  Bill

bob_buzzardbob_buzzard
I would expect all of the apex classes to show up with coverage, even if it was 0%.  Are the 16 missing classes the test classes? They won't show up as they aren't classes that are executed in production.
Bill McBill Mc
Yes it turns out I have 16 test classes.

So now how do I calculate the test coverage percentage?  Do I manually take the results of each and compute the average myself by summing the percentages and taking an average? 

Many thanks, Bill
bob_buzzardbob_buzzard
I guess so - I just aim for all the coverage to be green and as close to 100% for all classes and triggers - that way I know I have at least 75% as everything has at least 75%.