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
Siana DcruzSiana Dcruz 

How to write test class for Options?

Hi all,
I am not sure how to write test class for this method. Any help would be greatly appreciated!! 
    public List<SelectOption> getDiningTimeOptions()
        List<SelectOption> options = new List<SelectOption>();
        List<String> Times = this.getDynamicPicklistValues('Intake__c', 'Time__c');
        for (String Time : Times)
            options.add(new SelectOption(Time, Time));

        return options;
Martijn SchwarzerMartijn Schwarzer
Hi Siana,

Please try the following:
private class DiningTimeOptionsTest{

    static testmethod void testGetDiningTimeOptions(){


        //Create object instance of your class
        YourClass yc = new YourClass();

        //Call the method to test
        List<SelectOption> timeOptions = yc.getDiningTimeOptions();


        //perform assertions to test if method works correctly
        system.assertNotEquals(null, timeOptions, 'The selectoptions list should be instantiated');

Hope this helps!

Best regards,
Martijn Schwärzer

Ps. If my answer helped you, please mark it as best answer. It will help others find best answer as well.