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
Neha KakrooNeha Kakroo 

Can somebody help me in writing the test class for the code (SelectOption class)

Hi,

 

I am not sure how to test this code. I dont know how to use the SelectOption in the test class. Can somebody tell me how should i write it??

 

 

public with sharing class ctrl_MultiSelectPickList 
{
    public String Label{get; set;}
    
    public List<String> selected{get; set;}
    public List<String> deselected{get; set;}

    public SelectOption Available { get; set; }
    public SelectOption Chosen { get; set; }
    
    public List<SelectOption> selectedOptions = null;
    public List<SelectOption> AllOptions = null;

    // A Reference list (all options)
    List<Options> opt{get; set;}
 
    public List<SelectOption> getselectedOptions()
    {
        return selectedOptions;
    }
    public void setselectedOptions(List<SelectOption> value)
    {
        selectedOptions = value;
    }

    public List<SelectOption> getAllOptions()
    {
        return AllOptions;
    }
    
    public void setAllOptions(List<SelectOption> value)
    {
        AllOptions = value;
    }


    public class Options
    {
        public Integer Index{get; set;}
        public String Item{get; set;}
    }

_Prasu__Prasu_

Create the instance of class "ctrl_MultiSelectPickList" and call out methods in that class.

Shashikant SharmaShashikant Sharma

Here is your test class 100% code coverage, I hope will solve your issue.

 

@isTest
private class ctrl_MultiSelectPickListTest{

    private static testMethod void testctrl_MultiSelectPickList()
    {
        ctrl_MultiSelectPickList cls = new ctrl_MultiSelectPickList();
        List<SelectOption> so = new List<SelectOption>();
        so.add(new SelectOption('Test Option', 'Test Option'));
        cls.setselectedOptions(so); 
        List<SelectOption> resultOptions = cls.getselectedOptions();
        cls.setAllOptions(so); 
        resultOptions = cls.getAllOptions();
        ctrl_MultiSelectPickList.Options innerCls = new ctrl_MultiSelectPickList.Options();
    } 

}

 You can read these too know how to write a test class.

 

http://forceschool.blogspot.com/search/label/Test%20Apex

 

Let me know if any issues.

Neha KakrooNeha Kakroo

Thanks Shashikant !! this was really helpful :)

Shashikant SharmaShashikant Sharma

Your welcome Neha

 

Please mark it as accepted solution, so that it helps others also.