I am having multiple test classes for one apex class .

If I run one test class it gives overall coverage for the apex class as 50% . By running other test class it drops down to 30 %. My basic doubt is about this calculation .How is the overall test coverage calculated for the apex class .Does it takes average of all the test classes run ? Also what about the methods which are common in different test classes .

Thanks in advance

1 Answer 1


Nor average, neither sum of percents. If some test methods cover one line of code twice, it only means that this exact line of code is covered.

So the actual test coverage is linesCovered / allLines * 100.

Example: imagine 1st test class covers one method in your controller (30%), 2nd test class covers 2 methods including the previous mentioned one (50%), if you run both classes you'll get 50% again, because number of covered lines will not increase.

You must log in to answer this question.

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