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

My First Controller - Please review and assist with test method
I just finished my first controller class. I am creating a Customer Webform for customer's to fill in when they have issues with their orders. My first goal is to capture all these inquiries in a customer object called Email Log. I have already set up the object with all the necessary fields. To control the type of data the customer's fill in I have a few picklist fields with set values. For the purposes of this controller I am starting with a field called further_details__c. I was hoping somebody with more experience could look at my code and let me know if anything needs to be changed. I was also hoping to get some help with building a test method so I can deploy it.
public class WebformIssuesOptions {String[] further_details = new String[]{};
public PageReference test() {
return null;}
public List<SelectOption> getItems(){
List<SelectOption> options = new List<SelectOption>();options.add(
new SelectOption('Gift Card being shipped to another Country','Gift Card being shipped to another Country'));options.add(new SelectOption('Image/Quality Issue','Image/Quality Issue'));options.add(
new SelectOption('Issue Retrieving E-Certificate','Issue Retrieving E-Certificate'));options.add(new SelectOption('Need to Address/Ship Date','Need to Address/Ship Date'));options.add(
new SelectOption('Order Inquiry','Order Inquiry'));options.add(new SelectOption('Order Not Received','Order Not Received'));options.add(
new SelectOption('Order Placed from another Country','Order Placed from another Country'));options.add(new SelectOption('Website Issues','Website Issues'));
return options;}
public String[] getfurther_details(){ return further_details;
}
public void setfurther_details (String[] further_details){ this.further_details = further_details;
}
}
Is this better:
public class WebformIssuesOptions { String[] further_details = new String[]{}; public PageReference test() { return null; } public List<SelectOption> getItems(){ List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('Gift Card being shipped to another Country','Gift Card being shipped to another Country')); options.add(new SelectOption('Image/Quality Issue','Image/Quality Issue')); options.add(new SelectOption('Issue Retrieving E-Certificate','Issue Retrieving E-Certificate')); options.add(new SelectOption('Need to Address/Ship Date','Need to Address/Ship Date')); options.add(new SelectOption('Order Inquiry','Order Inquiry')); options.add(new SelectOption('Order Not Received','Order Not Received')); options.add(new SelectOption('Order Placed from another Country','Order Placed from another Country')); options.add(new SelectOption('Website Issues','Website Issues')); return options; } public String[] getfurther_details(){ return further_details; } public void setfurther_details (String[] further_details){ this.further_details = further_details; } }
This seems pretty straight forward. A test method might look like this:
public class WebformIssuesOptions {
String[] further_details = new String[]{};
public PageReference test() {
return null;
}
public List<SelectOption> getItems(){
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Gift Card being shipped to another Country','Gift Card being shipped to another Country'));
options.add(new SelectOption('Image/Quality Issue','Image/Quality Issue'));
options.add(new SelectOption('Issue Retrieving E-Certificate','Issue Retrieving E-Certificate'));
options.add(new SelectOption('Need to Address/Ship Date','Need to Address/Ship Date'));
options.add(new SelectOption('Order Inquiry','Order Inquiry'));
options.add(new SelectOption('Order Not Received','Order Not Received'));
options.add(new SelectOption('Order Placed from another Country','Order Placed from another Country'));
options.add(new SelectOption('Website Issues','Website Issues'));
return options;
}
public String[] getfurther_details(){
return further_details;
}
public void setfurther_details (String[] further_details){
this.further_details = further_details;
}
static testmethod void controllerTest() {
WebformIssuesOptions wio = new WebformIssuesOptions();
List<SelectOptions> options = wio.getItems();
System.assertEquals(options.size(), 8);
String[] details = new String[1];
details[0] = 'test';
wio.setFurther_Details(details);
System.assertEquals(wio.getFurther_Details[0], 'test');
}
}
Thank you for the test code. It is really appreciated. However I am still running into errors.
For this code:
System.assertEquals(wio.getfurther_details[0], 'test');
I am getting this error:
Save error: Variable does not exist: getfurther_details
I am also getting an error that states my test coverage is 73%.