You need to sign in to do that
Don't have an account?

Testing getter-setter and SelectOptions methods
This is a controller extension which has a custom save method to commit the value of userClick to the database.
1. How do I test userClick
2. How do I test the SelectOptions method of UserOption dropdown values.
Controller Extension for standardsetcontroller
public with sharing class BulkUpdate {
//Global Variables
private ApexPages.StandardSetController controller;
Public String userClick { get; set; }
// Standard Set Controller Constructor
public BulkUpdate(ApexPages.StandardSetController Controller) {
this.controller = controller;
}
public List<Case> getSelected(){
return (List<Case>) controller.getRecords();
}
//getOptions for userClick Method
public List<SelectOption> getUserOptions(){
List<SelectOption> useroptions = new List<SelectOption>();
useroptions.add(new SelectOption('','--select--'));
useroptions.add(new SelectOption('Next','Next RC'));
useroptions.add(new SelectOption('Next-Complete','Next-Complete'));
useroptions.add(new SelectOption('Previous','Previous RC'));
useroptions.add(new SelectOption('Refresh','Refresh Case'));
return useroptions;
}
//Save and Next method
public PageReference SaveNext(){
for(Case a :getSelected()){
a.UserActions__c=userClick;
}
Update getSelected();
PageReference pageRef = page.BulkUpdate2;
pageRef.setRedirect(true);
return pageRef;
}
}
Relevant Visualforce code:
<apex:selectList Label="UserActions" value="{!userClick}" size="1"> <apex:selectOptions Value="{!userOptions}"/> </apex:selectList>
thecontroller controller = new thecontroller();
controller.getUserOptions();
controller.userClick = 'option here';
All Answers
thecontroller controller = new thecontroller();
controller.getUserOptions();
controller.userClick = 'option here';
Thanks - here is my test code for this - but it isn't passing or improving my controller test coverage. Any suggestions?
@isTest
private class BulkPageClicksTest {
static testMethod void TestBulkUpdateNextClicks(){
List<Case> cases = new List<Case>{};
for(Integer i = 0; i < 200; i++){
Case c = new Case(XLS01__c=TRUE);
cases.add(c);
}
Insert cases;
PageReference pageRef = Page.BulkUpdate2;
Test.setCurrentPage(pageRef);
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(cases);
test.startTest();
BulkUpdate2 e = new BulkUpdate2(ssc);
e.getUserOptions();
e.userClick='Refresh';
e.getAdminOptions();
e.adminClick='Refresh';
e.getCancelOptions();
e.cancelClick='test';
e.SaveNext();
cases = [Select Id,Cancellation_Reason__c, AdminActions__c, UserActions__c FROM Case Where Id IN: cases];
System.assertEquals('Refresh',cases[0].UserActions__c);
System.assertEquals('Refresh',cases[0].AdminActions__c);
System.assertEquals('test',cases[0].Cancellation_Reason__c);
test.stopTest();
}
}
What is the error when you run the test?
Running the test from the salesforce interface failed the test.
However - from the developer console - it succeeded and there were no errors.
Thanks for your help!