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
prady-cmprady-cm 

Test coverage on get methods

Hi,

 

How can i have coverage on get methods in a controller?

 

	public List<SelectOption> Listtype
	{
		get
		{
			List<SelectOption> Val = new List<SelectOption>();
                        Val.add(new SelectOption('First', 'One'));
                        Val.add(new SelectOption('second', 'two'));
                        Val.add(new SelectOption('Third', 'three'));
                        return Val;
			
			}
}

 Any pointers

Best Answer chosen by Admin (Salesforce Developers) 
SeAlVaSeAlVa

I guess you will need to use something like the following

List<SelectOption> dummy = controller.Listtype;
// or
List<SelectOption> dummy = controller.getListtype();

 Regards

All Answers

SeAlVaSeAlVa

I guess you will need to use something like the following

List<SelectOption> dummy = controller.Listtype;
// or
List<SelectOption> dummy = controller.getListtype();

 Regards

This was selected as the best answer
RonakPatel.ceRonakPatel.ce

Hi,

 

See your Solution.

 

public class main{
public List<SelectOption> Listtype
{
get
{
List<SelectOption> Val = new List<SelectOption>();
Val.add(new SelectOption('First', 'One'));
Val.add(new SelectOption('second', 'two'));
Val.add(new SelectOption('Third', 'three'));
return Val;

}
}
Private Static testmethod void Testclass()
{
main test = new main();
List<SelectOption> Values= test.Listtype;

}
}

DeepeshDeepesh

You can also create a pagereference in your test class

  pageRef = Page.Opp_PAgeName;
     Test.setCurrentPage(pageRef);
     
     ApexPages.StandardController sc = new ApexPages.StandardController(opp);
    ControllerClass controller = new ControllerClass (sc);