Print this page

Why am I getting deployment errors due to code coverage when my organization's test code coverage is above 75?

Knowledge Article Number 000187272
Starting Winter 14, I see a new link "Estimate your organization's code coverage".
When I click this link it shows my test code coverage above 75%.
But when I deploy, I get test code coverage under 75%. 
a) Why am I seeing such discrepancy?
b) Which code coverage % is accurate - the one shown by the link or the one shown in deployment?

In Winter 14, we changed the link name from "Calculate your organization's code coverage" to "Estimate your organization's code coverage".
As the name suggests, it's an estimate and not the true number.
Reason: During deployment when user is getting different components in Salesforce, the test code coverage calculation will be done in real time and cannot be done before hand.
Example: I have 100 classes in my org and my test code coverage is 80%.
I deploy 50 classes and they don't have test classes.
Think by how much % the test code coverage will go down and that's can't be predicted till you actually start a deployment.
The new calculation will be done based off (100+50) classes during deployment.
Test code coverage for 100 classes was 80% but not for 150.
You shouldn't rely on the link "Estimate your organization's code coverage" during deployment.
The calculation will be different during deployment based off the components you are deploying.
Even a small change will impact the test code coverage.
The number you see during deployment is accurate and based off the current components in the org and the new components you are deploying.

Here are the list of components that trigger "run all tests" during deployment and impact the test code coverage-

More information to find how tests are calculated-

Best practices for writing a test class to increase test code coverage- 
How to resolve the test code coverage issue during deployment-
a) Identify test classes that have code coverage under 75.
Work on getting their test code coverage above 75%.

b) Identify classes that don't have test classes.
Work on getting test classes for them.

c) You will need to push test classes till the test code coverage goes above 75% for the org.

promote demote