2

I am having an issue when loading a page, a controller and its test class to production environment. The deployment always fails due to a lack of code coverage (66% when 75% is the minimum), even though the controller is covered at 84%. Also, the code coverage for the production environment is estimated at 86%.

One thing that I have noticed is that there are only two non-managed test classes in the environment and about 1000 managed test classes. However, when I deployed the components only 16 test classes are run. I have done another deployment on the same environment where only 8 test classes were run. I am not sure what causes the difference in the number of test classes run. I am guessing this might be the cause of the code coverage issue.

Any help on these two items will be appreciated.

Thanks,

Waly.

  • What version code are you using? Are you using @seeAllData=true? If you are, it could be using existing data in the Sandbox and there isn't any that correlates in production. If that is the case, you should remove the seeAllData and write better tests by creating your own data for them through code. – dphil Apr 13 '15 at 15:34
  • Has your production environment changed since you created your sandbox? You may need to save your code to Eclipse, etc and then refresh your sandbox – crmprogdev Apr 13 '15 at 15:34
  • @dphil I am using seeAllData=true, and the test data I need is already present in production. However, I will follow your suggestion and let you know if it helps. – Waly Apr 13 '15 at 16:09
  • @Waly Generally you don't want to use the seeAllData. There are only specific cases where you would and usually that deals with Pricebooks. I think newer versions thought might even have fixed that. – dphil Apr 13 '15 at 16:11
  • @crmprogdev I don't own the environments so refresh is not an option. Thanks! – Waly Apr 13 '15 at 16:13
2

UPDATE: SOLUTION (4/16/15)

  1. Clear Test History:

    (Setup->Apex Test Execution-> click link 'View Test History'->click button 'Clear Test Data')

    NOTE: The 'Clear Test Data' button completes the following 2 actions:

    • Deletes all entries from the ApexCodeCoverage table

    • Resets all the entries in the ApexCodeCoverageAggregate table to have 0 lines covered and all lines marked as uncovered This will result in seeing 0% code coverage in the Organizations estimation

  2. Manually clear entries for the 'ApexCodeCoverageAggregate' table:

    Via the Developer Console, execute the following query under the 'Query Editor' tab, using the 'Tooling API':

    SELECT Id FROM ApexCodeCoverageAggregate

    NOTE: Ensures there are no corrupt/invalid counts in the lines per class.

    A) Highlight every row returned and click the button 'Delete Row'

    B) Ensure there are no records in the 'ApexCodeCoverageAggregate' table by re-running the same query above in step 2 or hitting by the 'Refresh Grid' button as mentioned in the note above.

    NOTE: This process is asynchronous. Keep checking this by pressing the 'Refresh Grid' button in the Developer console until all rows are cleared.

  3. Recompile all Apex classes:

    Do this via 'Compile All Classes' link in UI (Setup->Develop->Apex Classes->click link 'Compile all classes')

  4. Run All Test

    Now with the tables/cache clear we re-run again via the 'Run All Tests' button in UI (Setup->Develop->Apex Classes->click button 'Run All Tests')

Full step-by-step details provided here:

Code coverage steps and considerations prior to deployments


ORIGINAL RESPONSE

I've been dealing with this issue for the past few weeks now, I've got a running answer listed here: Develop Console Code Coverage Issues (Winter 15' Release) - Production vs. All Test

I'm willing to bet that Winter 15' made some changes to Unit Test to include things they already should have, for example seeAllData=true test do not count towards code coverage, but in your estimated 86% you will see it counted. This only clarifies that there is a difference between perceived CC (Run All Test) and actual CC (Deployment to production)

There is an actual bug that SF has recognized but the patch is a few months out at least it sounds like. Checkout my post (link above) for more details as I have them

Also found this helpful article for clearing and getting accurate coverage amounts: https://help.salesforce.com/apex/HTViewSolution?urlname=Code-coverage-steps-and-considerations-prior-to-deployments&language=en_US

  • 1
    Thanks for sharing the resource! I was able to load the change set by modifying the test class. – Waly Apr 13 '15 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.