+ Start a Discussion
Victor19Victor19 

Need help writing test data for my controller

Hi,
I have a controller on my visualforce page and I am not able to build test data to cover for the coverage for the below variables. The data comes in from my visualforce page. Can someone please advise?

public class OppExtension{
    public OppExtension(ApexPages.StandardController controller) {
        std = controller;
        OpptyRec = (Opportunity)std.getRecord();
}

public string s1{get;set;}
    public string s2{get;set;}
    public string s3{get;set;}

public PageReference assignvalue(){
        s1 = s1.replace('North America (%) : ', '');
        s2 = s2.replace('APAC (%) : ', '');
        s3 = s3.replace('LATAM (%)  : ', '');
return null;
}
}
Thanks,
Victor
Best Answer chosen by Victor19
SujilaSujila
You can manipulate the test class like this:-
 
@isTest
public class TestOppExtension {
    public static testmethod void testOppExtensionMethod(){
        Opportunity opp =  new Opportunity(Name='Test Opp', StageName = 'Prospecting', CloseDate = System.today());
        insert opp;
        ApexPages.StandardController stdController  = new ApexPages.StandardController(opp);
        OppExtension ocontroller = new OppExtension(stdController );
        ocontroller.s1 = 'North America (%) : ';
        ocontroller.s2 = 'APAC (%) : ';
        ocontroller.s3 = 'LATAM (%)  : ';
        PageReference pr = ocontroller.assignvalue();
        System.assertEquals('', ocontroller.s1);
    }
}

 

All Answers

SujilaSujila
You can manipulate the test class like this:-
 
@isTest
public class TestOppExtension {
    public static testmethod void testOppExtensionMethod(){
        Opportunity opp =  new Opportunity(Name='Test Opp', StageName = 'Prospecting', CloseDate = System.today());
        insert opp;
        ApexPages.StandardController stdController  = new ApexPages.StandardController(opp);
        OppExtension ocontroller = new OppExtension(stdController );
        ocontroller.s1 = 'North America (%) : ';
        ocontroller.s2 = 'APAC (%) : ';
        ocontroller.s3 = 'LATAM (%)  : ';
        PageReference pr = ocontroller.assignvalue();
        System.assertEquals('', ocontroller.s1);
    }
}

 
This was selected as the best answer
Victor19Victor19
Thank you SRN_SalesForcing!. Your suggestion helped me out :). It bumped up my code coverage.
Victor