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
richardvrichardv 

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!');
 }

=======================================