How to cover PageReference method in test class in Salesforce?

How to cover PageReference method in test class in Salesforce?

Sample Apex Class:

public class Sample {
    public Sample() {
    }
    
    public PageReference goToInfallible() {
        PageReference pg = new PageReference(‘https://www.infallibletechie.com’);
        pg.setRedirect(true);
        return pg;
    }
}


Test class:

@isTest
private class SampleTest {
    @isTest static void test() {
        Sample s = new Sample();
        s.goToInfallible();
    }
}

Cheers!!!

Leave a Reply