You need to sign in to do that
Don't have an account?
Any ideas on workaround for private helper methods in Test classes counting against code coverage?
Private helper methods in test classes count against code coverage (which IMHO is a bad thing). The below code is not deployable because it's code coverage is only 60%. Does anyone have an idea for rewriting this code so that the code coverage goes up to 100% (other than moving the code in assertNoErrorMessagesExist method into the test method of course)?
=======================================
public class AController {
public Id anId {get;set;}
public AController(){}
}
}
=======================================
=======================================
@IsTest
private class TestAController {
private static testmethod void testControllerWithNoId(){
AController controller = new AController();
assertNoErrorMessagesExist();
}
private static void assertNoErrorMessagesExist(){
List<ApexPages.Message> errorMessagesOnly = new List<ApexPages.Message>();
if(ApexPages.getMessages() != null && ApexPages.getMessages().size() > 0){
for(ApexPages.Message message : ApexPages.getMessages()){
if(message.getSeverity() == ApexPages.Severity.ERROR
|| message.getSeverity() == ApexPages.Severity.FATAL){
errorMessagesOnly.add(message);
}
}
}
System.assert(errorMessagesOnly.size() > 0,errorMessagesOnly.size() + ' error(s) exist!');
}
}
=======================================