Skip to main content

I'm trying to develop a Test Class to Cover the below Method:

public List<SelectOption> getlength(){

List<SelectOption> options = new List<SelectOption>();

if(var_SystemOfMeasurement =='Imperial System'){

cpl.Length_Units__c = 'Yards';

options.add(new SelectOption('','--Length--'));

options.add(new SelectOption('36','36'));

options.add(new SelectOption('18','18'));

}

else if((cpl.Currency__c == 'USD' || cpl.Currency__c == 'CAD') && var_SystemOfMeasurement == 'Metric System'){

cpl.Length_Units__c = 'Meters';

options.add(new SelectOption('','--Length--'));

options.add(new SelectOption('33','33'));

options.add(new SelectOption('16.5','16.5'));

}

else if((cpl.Currency__c == 'EUR' || cpl.Currency__c == 'GBP') && var_SystemOfMeasurement == 'Metric System'){

cpl.Length_Units__c = 'Meters';

options.add(new SelectOption('','--Length--'));

options.add(new SelectOption('30','30'));

options.add(new SelectOption('15','15'));

}

return options;

}

Honestly, I have not idea how to transfer cpl.Currency__c variable into my test class and how to develop this condition so far that I have done is made some system.assert, but they are not enough to cover all my class... after all insert below a snippet of my test class

ZT_Controller tst = new ZT_Controller(sc);

tst.getSystemOfMeasurement();

tst.var_SystemOfMeasurement='Imperial System';

system.assertEquals(tst.var_SystemOfMeasurement, 'Imperial System');

 
1 resposta
  1. 17 de mar. de 2018, 18:02

    If cpl variable is assigned from SOQL query on a custom/standard object then insert a new instance of this object in test method with Currency__c field.

    ObjectApi__c cpl = new ObjectApi__c;

    cpl.Currency__c == 'USD';

    insert cpl;

    tst.getlength();

     
0/9000