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
Mike Reynolds 6Mike Reynolds 6 

Testing a helper class called from a void method?

Hey, 

I have a basic trigger, with a facade class handling my business logic. In the facade, I have a void method that is calling another helper. My code is all good, and it does what I want, but I'm having an issue with my test class not covering the helper that is called from the facade. I'm thinking it may be due to the call being made from a void method. Here's the relevant code:

Trigger
trigger caseTriggerAll on Case (Before Insert, Before Update) {
        if (Trigger.isBefore) {
            CaseTriggerFacade.isBefore(Trigger.new);
        } 
}
Facade
public class CaseTriggerFacade {
    
    public static void isBefore(List<Case> casesToUpdate) {
        List<Case> caseList = new List<Case>();
		for (Case c :casesToUpdate) {
			if (c.description != null && c.description.trim() != '') {
				caseList.add(c);
			}
		}
		HelperCaseDescUpdate.descUpdate(caseList);
	}
}
Helper:
public class caseDescUpdate {
    public static void descUpdate(case[] cases) {
        for (case cse :cases){
            cse.description = cse.description.replace ('"Text to find a remove.', ''); 
        }
    }
}

Test Class:
@isTest
private class caseDescUpdateTestClass{
    static testMethod void validateCaseDescUpdate() {
       case cse = new case(
           description='Previous text. \n Text to find and remove.'
       );
       System.debug('Description before update: ' + cse.description);
       // Insert case
       insert cse;
       // Retrieve the new case
       cse = [SELECT description FROM case WHERE Id =:cse.Id];
       System.debug('Description after trigger fired: ' + cse.description);
       // Test that the trigger correctly updated the description
       System.assertEquals('Previous text.', cse.description);
    }
}

The trigger and facade are covered 100%, but I can't get coverage for the helper. Any ideas on how to get coverage? Thanks. 
-Mike






 
Raj VakatiRaj Vakati
I am getting 100% with this code for helper too
 
@isTest
private class caseDescUpdateTestClass{
    static testMethod void validateCaseDescUpdate() {
        case cse = new case(
            description='Previous text. \n Text to find and remove.' ,Status = 'New' , Origin = 'Phone'
        );
        System.debug('Description before update: ' + cse.description);
        // Insert case
        insert cse;
        
        
        
        // Retrieve the new case
        cse = [SELECT description FROM case WHERE Id =:cse.Id];
        System.debug('Description after trigger fired: ' + cse.description);
        // Test that the trigger correctly updated the description
        System.assertEquals('Previous text.', cse.description);
    }
}

 
Mike Reynolds 6Mike Reynolds 6
stupid mistake on my part. line 10 on the facade i'm calling the wrong class. Your comment made me think to check. Thanks for the help!