You need to sign in to do that
Don't have an account?

Helper Methods for Test Classes
Upon checking the code coverage of our APEX Classes, we've noticed that a few of our actual Test Classes are evaluated as well. We found out that this is because of the non-test methods with parameters in our Test Classes. These methods are really just helper functions for the Test Classes, but it's frustating that they are the ones that cause the Test Classes to be evaluated in the overall code coverage numbers. (as described in https://help.salesforce.com/apex/HTViewSolution?urlname=Why-is-a-Test-class-evaluated-as-part-of-the-Organization-s-Code-Coverage&language=en_US (https://help.salesforce.com/apex/HTViewSolution?urlname=Why-is-a-Test-class-evaluated-as-part-of-the-Organization-s-Code-Coverage&language=en_US))
Is there any work around here? We also found out that the same pattern is actually used in the examples from the Force.com Apex Code Developer's Guide and the APEX Workbook. See https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_testing_1.htm and https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_utility_classes.htm. Does this mean that we also have to create test classes for those test helper methods?
Thanks in advance,
Mishael
Is there any work around here? We also found out that the same pattern is actually used in the examples from the Force.com Apex Code Developer's Guide and the APEX Workbook. See https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_testing_1.htm and https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_utility_classes.htm. Does this mean that we also have to create test classes for those test helper methods?
Thanks in advance,
Mishael
That said, it's not clear to me why you're having a problem. The whole purpose of having that common utility method in a test class is to use it in tests, so you should have no trouble getting very high code coverage values for it. In fact, if the class is being considered, it should - if anything, be helping your overall code coverage estimates, no?
All Answers
That said, it's not clear to me why you're having a problem. The whole purpose of having that common utility method in a test class is to use it in tests, so you should have no trouble getting very high code coverage values for it. In fact, if the class is being considered, it should - if anything, be helping your overall code coverage estimates, no?
I know this is an old thread, but in case Mishael or anybody else is looking for a halfway decent solution to this, I found something that worked for me. There is an annotation that allows you to expose a class's variables to test classes that refer to it, @TestVisible. I was able to make a helper function for my test class by using the following pattern:
This still contributes to your code coverage metrics, but testing it is as easy as throwing an additional test case into your suite for the class that you are already testing.