According to the documentation:
Test classes (classes that are annotated with @isTest) are excluded from the code coverage calculation. This exclusion applies to all test classes regardless of what they contain—test methods or utility methods used for testing
However I am currently finding that to be false (not the case).
As you can see in the included image (not all classes included in image) all my non test classes have coverage of 100% with a few stragglers dus to overzealous catch blocks. In total, for non test methods I have a grand total of 27 lines uncovered.
The coverage indicates that 324 lines are uncovered.
In my classes annotated with @isTest there are 297 lines across all @isTest
annotated classes where the methods are not marked as test methods (Utility methods).
I have checked the code coverage from the Dev console, IntelliJ, the Setup UI and they all say the same thing 84.xx% total coverage.
I have cleared the test history, recompiled all classes, all the usual stuff.
Is the documentation wrong?
An example method in an @isTest
annotated class
private static PageReference setTestPageReference(){
PageReference pr = Page.Example_Page;
pr.getHeaders().put('Host','https://login.salesforce.com');
test.setCurrentPageReference(pr);
return pr;
}
The class that contains the above method has 0/5 line covered. When I add the testmethod
to the method definition, the class changes to have 0 uncovered lines and the code coverage for the entire org goes up by .01%
Basically it seems that code in a @isTest
annotated class IS being included in test coverage which is a problem since I have a large test Utility class annotated with @isTest
and none of the methods are marked as test methods.
So the Questions:
- Am I the only one observing this behavior?
- Should I worry about it?
- Any harm in adding the
testmethod
designation to the utility methods? (It feels wrong)