Sample Test Class Example

By | January 21, 2020

Hi,this program we have show sample test class for apex class

Apex Class

public class TestExample2 {
    public string industry{set;get;}
    public string rating{set;get;}
    public string ownership{set;get;}
    public void callme(){
        if(industry=='Energy'){
            rating = 'Warm';
            ownership = 'Public';
        }else{
            rating = 'Hot';
            ownership = 'Private';
        }
    }
}

Test Class

@isTest
private class TestExample2Test {
    static testMethod void testme(){
        TestExample2 t = new TestExample2();
        t.industry = 'Energy';
        t.callme();
        system.assertEquals('Warm', t.rating);
        system.assertEquals('Public', t.ownership);
        TestExample2 t2 = new TestExample2();
        t2.industry='Education';
        t2.callme();
        system.assertEquals('Hot', t2.rating);
        system.assertEquals('Private', t2.ownership);
    }    
}

Leave a Reply

Your email address will not be published. Required fields are marked *