function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Code Coverage Woes

We have a class that's listed like this in our org:


Version: 24.0

Status: Active

Size without Comments: 2076

Coverage: 14% (32/216)


This class is, in total, 38 lines, covered like this:


5 "white" lines, not counted.

10 "red" lines, not covered.

23 "blue" lines, covered.


How is it that the coverage could be this screwed up?

Ron HessRon Hess

I see this if i run tests from the IDE and then go into the setup area and look at the class.


basically the stats in the org record the data last time the tests were run in the org.


try running the tests in the org and see if this is updated




Thanks for the advice. We've been using the IDE and Setup in a mixed fashion to expedite the development cycle, but we always perform the Run All Tests feature in the browser. That's sort of what makes this awkward. The class itself hasn't been updated in a while, although we've tried making cosmetic changes (e.g. removing or adding blank lines, comments, etc), at which point it does reset to "No Code Coverage", but running the test again results in the same bizarre coverage. We actually have several classes that may be affected by this issue, but we haven't had time to run through all 220 tests that cover about 100 classes to verify the extent of this coverage discrepency (that just happens to be the worst offender, since it was at 14% total coverage).


I think I'll double-check though and make sure that it's actually updating the "last test date" value, and if not, we might raise a case with support. I feel bad about having to do that, as our project has been particularly troublesome for support already with the random "Internal Server Error" pages, failed installs, and so on.

Ron HessRon Hess

ok, learned a bit more today.


we have one class, we'll call Foo.cls.


Foo.cls is covered by 2 test classes, no problem right ?


when you run one test class it covers Foo.cls at 85%


when you run the second class class it covers Foo.cls at 40% 


When you run all tests the system reports that Foo is covered at 62% 


another example, one class has 100% coverage, unless i run all tests and then this class shows up at 96%


So, it appears that the system reports the AVERAGE of all tests that touch a class, not the MAX coverage.


this would not be my first guess, but it appears to be the case, in my org anyway.





The issue cleared up myseriously. The class now appears to report correctly. I'm not sure what changed recently (we are actively developing), but the class no longer reports the erroneous values... But I'll have to experiment and see if that may have happened.