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
SForceDeveloperSForceDeveloper 

Test methods for a wrapper class

I have used a wrapper class for selecting and deselecting a checkbox. But i am stuck when writing test methods for a wrapper class. How can we select/unselectt he value of a checkbox inside a test method? Please let me know

 

Thanks

gm_sfdc_powerdegm_sfdc_powerde

What do you mean by a wrapper for checkbox? Can you post some sample code here?

SForceDeveloperSForceDeveloper

Here is some sample code :

 

 <apex:outputPanel layout="block" style="overflow:auto;width:750px;height:250px">
            
                <apex:pageBlockSection title="Search Results" id="resultsBlock" columns="1">
                    <apex:pageBlockTable value="{!searchResults}" var="c" rendered="{!NOT(ISNULL(searchResults))}">
                   
                        <apex:column width="25px">
                            <apex:facet name="header">Select</apex:facet>
                            <apex:inputCheckbox value="{!c.checked}"/>
                        </apex:column>                       
                       
                        <apex:column value="{!c.cat.Name}" headerValue="Name"/>
                    </apex:pageBlockTable>
                </apex:pageBlockSection>
            </apex:outputPanel>

 

 

Wrapper class :

 

public class CategoryWrapper
    {
 
        public Boolean checked{ get; set; }
        public Boolean checked1{ get; set; }
        public string profileid { get; set; }       
        public profile cat { get; set;}
    
        public CategoryWrapper()
        {
            cat = new profile();
           ;
            checked1 = false;
        }
    
        public CategoryWrapper(profile c)
        {
            cat = c;
            profileid = c.Id;
           ;
            checked1 = false;
        }       
 
    
    }

Please let me know if you need any more information . Thanks!

Afzal MohammadAfzal Mohammad

Your test methods should look something like this.

 

 

static testmethod void testcase1(){
    CategoryWrapper obj = new CategoryWrapper();
    obj.checked = true;
    obj.checked1 = true;
}

static testmethod void testcase2(){
    Profile profile = [select id from .....];
    CategoryWrapper obj = new CategoryWrapper(profile);
    obj.checked = true;
    obj.checked1 = true;
}

 

 

Hope that helps.

 

Afzal