1

I'm doing the first major code deploy in this org.

  • Dev console tests tab shows overall coverage of 93% across all apex
  • Deploying all apex to production
  • Production has only 1 small apex class and it's test class
  • Production has no triggers
  • Production has no unmanaged packages

Validating the inbound change set gives a code coverage error saying I'm at 61%. There are no other errors in validation.

This all makes no sense - what are the common gotcha's I'm missing here?

Thanks,

Steve

5 Answers 5

8

One most important thing I would recommend is to check that all test classes are creating their own test data and do not rely on org's data.

4
  • That can impact my code coverage? Interesting.
    – sberley
    Commented May 19, 2015 at 2:45
  • 2
    yes, the data being used in test classes drives the execution path. So, based on data attributes the test execution can also skip important code blocks, lowering your overall code coverage.
    – Anshul
    Commented May 19, 2015 at 2:46
  • While this is true I am having a hard time accepting data dependency could reduce coverage from 93% to 61%. If anything it should result in failing test cases, not a drastic drop in the coverage (unless the test cases are not asserting conditions properly).
    – Mossi
    Commented Aug 10, 2015 at 19:20
  • Well.. based on your data values, your code execution logic will vary (based on your conditions). Hence, the overall code coverage can vary greatly. Test method failure will only occur in case of exceptions/ assertion failures.
    – Anshul
    Commented Aug 11, 2015 at 4:48
3

First try https://help.salesforce.com/apex/HTViewSolution?urlname=Code-coverage-steps-and-considerations-prior-to-deployments&language=en_US

If the issue persists then the issue may be because of the text class errors that are not listed while running the test classes such as not using unique username while inserting a new user for test purpose or the user trying to deploy classes which has a reference to a certain field that he doesn't have access. This usually occurs when we are deploying the changes running the specific test classes (4th option). If we are running all the test classes, the errors occurring in test class will be shown. So it is recommended you deploy the changes by running all the test classes.

0

Looks like some test classes/methods are missed in the change set you have uploaded to production so that you need to make sure that all test classes/methods which gave you 93% coverage are included/added in the change set before uploading the change set to production.

Hope this will help you.

0

Take a look at this article: Code coverage steps and considerations prior to deployments

Turns out code coverage is majorly impacted by the Summer '15 release. Once you remove historic test runs and clear things out as pointed out in the above article you should end up with the true coverage.

Another reason could be missing components in your changeset, as pointed out earlier by another poster.

1
  • thanks - the reason was that I didn't make my own test data (bad, I know), so logic that was being run in a sandbox didn't get called in production.
    – sberley
    Commented Aug 11, 2015 at 21:54
0

Common issue is the deployment user. Are you running tests in sandbox & deploying with different users/profile? If so, missing some permission for the deployment user, might reduce the coverage.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .