Skip to main content
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
2 answers
  1. May 10, 2016, 7:19 PM
    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);

    }

    }

     
0/9000