1

Am working on a package upload, while am creating new upload am getting Error as : Average test coverage across all Apex Classes and Triggers is 21%, at least 75% test coverage is required.

But when i run allthe test classes using Run All Tests am getting overall code coverage as 89%. Am unable to upload the package now. Please suggest.

1
  • 1
    Most likely you haven't included all the test classes in the package definition. Commented Dec 23, 2014 at 21:34

2 Answers 2

1

Refer this link: link

Found what was wrong with my coverage. There were no test classes written for a part of the project, so those classes never got called in any test class which lead to them being omitted from the list of classes covered and therefore them not being counted towards Overall coverage.

However, while uploading a package, after tests were run some classes didn't have any coverage at all which lead to Overall coverage being so low.

After writing a few more test classes(for the classes that were not tested), I got the coverage above 75%.

So if there are no test classes testing some class A, then this class A will neither show up in Overall Code Coverage class list, neither count towards it.

0

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


This question is being asked multiple times in different ways right now all because of a common issue.

I have a very detailed post and answer posted here: Develop Console Code Coverage Issues (Winter 15' Release) - Production vs. All Test

And again the same question was asked here as well: Low code coverage, when production and new test class to deploy are over 80%?

As I mention to others, keep in mind there is a difference between perceived code coverage (running all test) and actual code coverage which happens during deployment. Hopefully my post will shed some light on your issue.

Also keep in mind:

  • If you have utility type methods in your @isTest classes BUT those methods are not test methods themselves then they are counting against your total coverage even though the develop console doesn't reflect that
  • The same goes for any method with the (SeeAllData = true) declaration. So if you have a lot of those that could be an underlying issue as well.

You must log in to answer this question.

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