Code Coverage Calculation - Seems to be including code in test methods
I've had similar conversations about this before with salesforce, because this was actually causing us issues in deployment. What we came away with was as follows.
The Documentation is Correct
According to Support, any class that has @isTest specified should be completely exempt from code coverage. It should display as 0/0 coverage.
The System is Wrong
They confirmed with R&D that someone internally has already logged a bug regarding this. There is a Known Issue that's tracking this bug.
We Should Test (For Now)
In our case, we had nearly 500 lines of code that were showing no coverage, and it was actually causing deployments to fail with a net total of 74% coverage. If you're getting deployment errors, then you need to unit test your unit tests. Otherwise, don't worry about it.
Am I the only one observing this behavior?
You are not. There is at least one relevant Known Issue
: Non-test methods in a test class are counted as part of Apex code Coverage. It seems that if you create a class, then add the @IsTest
definition after the fact, that can contribute to the issue.
Should I not worry about it?
I believe this bug does not affect deployments to production, which is generally the most critical time to have accurate code coverage numbers. I believe it would be unlikely to follow the reproduction steps listed in the Known Issue I linked to, since you would have to deploy a class as live and then convert it to the @IsTest
annotation.
Any harm in adding the testmethod designation to the utility methods?
Security scanners will certainly frown upon test methods with no assertions. I'd avoid it.