function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Javier MaldonadoJavier Maldonado 

Facing issues to test an IF condition in a Class

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');

 
Om PrakashOm Prakash
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();