I'm having a very odd issue pop up wherein if I put all 75 of my account testMethods in one class, I get less than stellar coverage (maybe 70%) but if I split those testMethods up into 8-10 smaller classes (same 75, but split) then I get higher coverage (upwards of 90-95%)

This is in the sandbox

Is this just a glitch in the way they calculate code coverage in test? Or is this actually something I need to pay attention to and not allow more than x testMethods per class?

  • Are you by chance getting those total coverage figures from Run All Tests or from the Developer Console or org estimation? Commented Mar 30, 2015 at 21:50
  • 2
    I would open a case by salesforce for sure. It is pure coverage bug. Commented Mar 30, 2015 at 21:54
  • 1
    That's good. The aggregate result mode is usually less accurate.
    – sfdcfox
    Commented Mar 31, 2015 at 15:00
  • 2
    Have you tried Test > Clear Test Data in the dev console? I've noticed that it sometimes caches results, and they're reported incorrectly.
    – powlo
    Commented Aug 26, 2015 at 11:49
  • 1
    Do the both classes have the same version? Did you solve this issue?
    – Patlatus
    Commented Mar 8, 2016 at 12:18

4 Answers 4


Distilling the comments:

  1. Clear out all the test coverage and try running it all from scratch. There can be caching issues with previous test runs. See How to eliminate bad code coverage data for apex classes ?
  2. Avoid the “Store Only Aggregated Code Coverage” option for test runs unless your volume of tests requires it.
  3. Consider disabling parallel testing. Also accessible via the Apex Test Execution Options page.
  4. Compile all the classes before running the tests.
  5. Check that the API versions for the test class and the class being tested are the same.

Apex Test Execution Options

If those steps fail you, raise a support case with Salesforce.

See also:


That's really odd, although the test coverage % results are really just estimates. That might be what you're running into, where salesforce is calculating it differently because it's in 1 big class vs separate classes. Doesn't make a lot of sense to me, but if you're really concern you're best bet is to submit a support case. You might also want to try the developer boards.


It does happen sometimes. I guess the most likely reason is about test data which will be different between all tests and separate tests.

  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post
    – cropredy
    Commented Apr 30, 2016 at 17:15

I am not 100% sure but If your class has if else blocks it would cover either if or else even though you have data for both the conditions. This happens when your class is being called by trigger and you do not call it directly in the test class. And in such a case you are needed to do it in separate test methods.

You must log in to answer this question.

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