Test class for Abstract class in Salesforce

Test class for Abstract class in Salesforce

Abstract Class:


public abstract class SampleAbstract
{
    public Task newTask;
    public void createT(Id caseId, Id accountId)
    {
        newTask = new Task();
       
        methodX();
        methodY();
    }
   
    public abstract void methodX();
    public abstract void methodY();
}


Class extending Abstract class:


public class Sample extends SampleAbstract {  
   
    public sample() {
    }
   
    public override void methodX(){
    }
   
    public override void methodY(){
    }  


}


Test class:


@isTest
private class AbstractTest{
    static testMethod void test(){
        Sample sa = new Sample();  
           
        Id caseId;
        Id accountId;
        sa.createT(caseId, accountId);  
    }
}

2 thoughts on “Test class for Abstract class in Salesforce

  • I have a VF page, VF component & their separate controllers. Both controllers are extending 2 virtual classes. In sObject is passed to VF Component using . I don't understand how to write test class to cover them. Can you please give an idea ? Thank you very much. Appreciate your help.

Leave a Reply