Test Class for Static Method in Apex in Salesforce

Test Class for Static Method in Apex in Salesforce

Sample Test Class:

@isTest
private class testClass
{
    static testMethod void test()
    {
        Member__c m = new Member__c();
        m.Name = ‘Sample’;
        m.Email_Address__c = ‘
Your email address‘;
        m.Age__c = 25;
        insert m;
        memberApproval.callApproval(m.Id);
    }
}

here memberApproval is an Apex class and callApproval is a static method.

To call a static method in a test class, we have to use class name instead of object of that class.

Cheers!!!

Leave a Reply