0

How to test a List<SelectOtion> in unittest. I have the following apexclass

    public class WebToObjAttachments {
    ..
        public List<SelectOption> CountryOptions {
        get {
                List<SelectOption> options = new List<SelectOption>();
            if(!urlvalue.contains('_NL')){
                options.add(new SelectOption('NL', 'Netherlands')); 
                for (Schema.PicklistEntry pe : SObjectType.Lead.fields.CountryCode.getPicklistValues()) {

                }
                options.add(new SelectOption('BE', 'Belgium')); 
                options.add(new SelectOption('FR', 'France')); 
                options.add(new SelectOption('DE', 'Germany')); 
                options.add(new SelectOption('ES', 'Spain')); 
                options.add(new SelectOption('PT', 'Portugal')); 
                options.add(new SelectOption('IT', 'Italy')); 
                options.add(new SelectOption('GB', 'United Kingdom')); 
                options.add(new SelectOption('SCOT', 'Scotland')); 
                options.add(new SelectOption('IE', 'Ireland')); 
                options.add(new SelectOption('US', 'United States')); 
            }
         return options;
} 
    set;}
    ..
    }

I have tried the following but get the error: public is not allowed on locals

private static testMethod void CountryOptionsTest()
{
    property__c prop = new property__c();
    prop.name = 'Testproperty';
    insert prop;

    Lead le=new Lead(Lastname='Unit Test', RecordType__c = 'Guest');
    insert le;
    ApexPages.StandardController sc = new ApexPages.standardController(le);
    WebToObjAttachments controller = new WebToObjAttachments(sc);

    public List<SelectOption> testoptions = controller.CountryOptions ;

}
2

Error: public is not allowed on locals:

Reason

That error is coming because inside the private static method you have declared public selection Option

removed public keyword from

    List<SelectOption> testoptions = controller.CountryOptions ;

Code:

public static testMethod void CountryOptionsTest()
 {
property__c prop = new property__c();
prop.name = 'Testproperty';
insert prop;

Lead le=new Lead(Lastname='Unit Test', RecordType__c = 'Guest');
insert le;
ApexPages.StandardController sc = new ApexPages.standardController(le);
WebToObjAttachments controller = new WebToObjAttachments(sc);
List<SelectOption> testoptions = controller.CountryOptions ;}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.