3

Given two classes with test classes:

  1. 400 testable lines: 200 covered
  2. 10 testable lines, 10 covered

How will the test coverage be calculated? Average of the coverage for each class, or the ratio of all tested lines together to the total amount of code in the org?

First method: class one has 200/400 = 50% coverage, class two has 10/10 = 100% coverage. Average is (50% + 100%)/2 = 75%, which meets the minimum requirements for production deployment.

Second method: 200 + 10 = 210 covered lines, 400 + 10 = 410 total lines. Coverage is 210/410 = 51.2%, which is too low.

I did read How is Total code Coverage on ApexClass calculated as well as the linked blog post How Code Coverage Works, but neither seem to address this specific question. That is, I have not seen an example like the one in this question.

My current task is to pick up the slack left behind by an overly-aggressive development schedule. I need to know if it is worth squeezing an extra line of coverage from a small class, or extend the same effort to cover ten lines in a large class (I assume larger classes have more opportunities to cover odd sections of code, which has proven true on this project so far).

1 Answer 1

4

It is 75% of your code which means in your given example, the second method. Adding another extra line and test coverage for that line will not increase your test coverage dramatically. It works based on number of lines of code and not percentage per class.

1
  • 1
    Thanks, that is what I suspected. If I were in charge of the calculation, that is what I would have chosen. However, I wanted to be certain.
    – user6861
    Commented Aug 27, 2014 at 1:16

You must log in to answer this question.