Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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).

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
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. –  Snowman Aug 27 at 1:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.