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
Soundar Rajan PonpandiSoundar Rajan Ponpandi 

How to cover a test class for this simple class ?

Hi,

How to cover a test class for followig apex class.
 
Apex Class
__________________________

public without sharing class GD_RemoveProcessRecords {

    public static void removeProcess(List<Approval.ProcessWorkitemRequest> requests){
         Approval.process(requests, true);
    }
}

Test Class
 
@isTest
public class GD_RemoveProcessRecordsTest {
    
    static testMethod void removeProcessTestMethod() {
        
        Account acc1 = GD_TestDataFactory.createCustomer('Acc1','Customer');
        acc1.GD_Pharma_Location__c = 'Dubai';
        acc1.GD_Pharma_Account__c = true;
        Insert acc1;

        
        GD_Order__c ord = new GD_Order__c(GD_Account__c = acc1.id);
        insert ord;
        
        Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
        req.setComments('Submitting request for approval.');
        req.setNextApproverIds(new Id[] {UserInfo.getUserId()});
        req.setObjectId(ord.Id);
        Approval.ProcessResult result =  Approval.process(req);
        
        test.startTest();
        //GD_RemoveProcessRecords.removeProcess(new List<Approval.ProcessWorkitemRequest>{req});
        test.stopTest();
    }
    
}

Thanks in advance,
Soundar.​​​​​​​
ANUTEJANUTEJ (Salesforce Developers) 
Hi Soundar,

In the test method, I think you will have to call the method that you will have to call the method with appropriate values that are necessary for the method to run.

I hope this helps and in case if this is useful can you please choose this as the best answer so that it can be used by others in the future.

Regards,
Anutej