Assume you have 2 classes, A and B, each with 10 methods of equal length. You write 2 test classes, TestA and TestB, each running all 10 methods and producing 100% coverage.

However, when run from TestB, class B calls 2 methods of class A.

So when you run TestA and then look at coverage, class A is covered at 100%. When you run TestB and then look at coverage, class B is covered at 100%, and class A is covered at 20%.

Is there any way to prevent recalculation of dependent class coverage when testing? Is there any way to sequence tests into a specific order? Is there any way to prevent Apex from mistakenly reducing the coverage on a class when it is used indirectly while testing another class? Is there any other workaround for this issue?

1 Answer 1


That's not how unit tests work. The lines tested in each test will be cumulatively covered. You can view the results for an individual test (assuming you turn off "Store Only Aggregate Test Data"), but the coverage will still be correct. I wrote a mock up in my developer org that proves it works correctly. However, if you're having problems, I recommend going to Setup > Develop > Apex Test Execution > View Test History > Clear Test Data, then run all your tests again. Rarely, the server will get the coverage wrong, but clearing the history and running your tests should set things right again.

  • Clearing the history appears to have fixed the problem. It may also be that the problem was specific to the Mavensmate coverage report; I didn't look in developer console to see if it was doing the same thing. Sep 11, 2015 at 19:48
  • @aginghippie Mavensmate and Force.com IDE both rely on the Metadata API. It only returns coverage for tests executed. You need to actually check the stored code coverage on the class using the Tooling API or the UI.
    – sfdcfox
    Sep 11, 2015 at 20:51
  • Marking this as answer, because clearing the history was the solution. Sep 11, 2015 at 22:25

You must log in to answer this question.

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