Code Coverage in one big class vs multiple smaller classes

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?


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:

Source : Link , Question Author : Nathan Williams , Answer Author : Daniel Ballinger

Leave a Comment