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
DennoPDennoP 

How do I get test coverage on my radio button option?

I have a VF page with 5 radio buttons on.  For the answer I use a radio button (see page item below).  

 

My question is how do I test this because when I run my test class it doesn't touch this part of the the controllers List<SelectOption> part of the code?

 

Page item :

<apex:selectradio value="{!question1}" >
         <apex:selectOptions value="{!QuestionItem}" />
</apex:selectRadio>

 

Controller item :

 

// Question radio buttons
public List<SelectOption> getQuestionItem() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('0','0'));
options.add(new SelectOption('1','1'));
options.add(new SelectOption('2','2'));

return options;
}

 

Test Class :

// Test 1

MyController controller1 = new MyController();
controller1.question1 = 1;

controller1.save();

 

Any help is appretiated.  If I need to add more info just let me know as this is not all of the code just the bits I thought relevant.

 

Best Answer chosen by Admin (Salesforce Developers) 
Arunkumar.RArunkumar.R

Hi,

Test coverage for you question,

MyController cls = new MyController();
List<SelectOption> selOpts=cls.getQuestionItem();

where MyController is your class name...

 

If this post was helpful to you please mark this as a solution and give kudos....

 

Thanks and Regards,

Arunkumar.R | Salesforce Certified Force.com Developer.

 

All Answers

Arunkumar.RArunkumar.R

Hi,

Test coverage for you question,

MyController cls = new MyController();
List<SelectOption> selOpts=cls.getQuestionItem();

where MyController is your class name...

 

If this post was helpful to you please mark this as a solution and give kudos....

 

Thanks and Regards,

Arunkumar.R | Salesforce Certified Force.com Developer.

 

This was selected as the best answer
DennoPDennoP

Great.

 

Thanks very much this worked straight away.  Much appreciated.