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

Test method for List<SelectOption>
System.Exception: Assertion Failed: Expected: (System.SelectOption[value="01", label="Jan", disabled="false"], System.SelectOption[value="02", label="Feb", disabled="false"], System.SelectOption[value="03", label="Mar", disabled="false"], System.SelectOption[value="04", label="Apr", disabled="false"], System.SelectOption[value="05", label="May", disabled="false"], System.SelectOption[value="06", label="Jun", disabled="false"], System.SelectOption[value="07", label="Jul", disabled="false"], System.SelectOption[value="08", label="Aug", disabled="false"], System.SelectOption[value="09", label="Sep", disabled="false"], System.SelectOption[value="10", label="Oct", disabled="false"], ...), Actual: (System.SelectOption[value="01", label="Jan", disabled="false"], System.SelectOption[value="02", label="Feb", disabled="false"], System.SelectOption[value="03", label="Mar", disabled="false"], System.SelectOption[value="04", label="Apr", disabled="false"], System.SelectOption[value="05", label="May", disabled="false"], System.SelectOption[value="06", label="Jun", disabled="false"], System.SelectOption[value="07", label="Jul", disabled="false"], System.SelectOption[value="08", label="Aug", disabled="false"], System.SelectOption[value="09", label="Sep", disabled="false"], System.SelectOption[value="10", label="Oct", disabled="false"], ...)
public class Months {
public List<SelectOption> getMonthList() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('01', 'Jan'));
options.add(new SelectOption('02', 'Feb'));
options.add(new SelectOption('03', 'Mar'));
options.add(new SelectOption('04', 'Apr'));
options.add(new SelectOption('05', 'May'));
options.add(new SelectOption('06', 'Jun'));
options.add(new SelectOption('07', 'Jul'));
options.add(new SelectOption('08', 'Aug'));
options.add(new SelectOption('09', 'Sep'));
options.add(new SelectOption('10', 'Oct'));
options.add(new SelectOption('11', 'Nov'));
options.add(new SelectOption('12', 'Dec'));
return options;
}
static testMethod void testMonthList() {
List<SelectOption> test_options = new List<SelectOption>();
test_options.add(new SelectOption('01', 'Jan'));
test_options.add(new SelectOption('02', 'Feb'));
test_options.add(new SelectOption('03', 'Mar'));
test_options.add(new SelectOption('04', 'Apr'));
test_options.add(new SelectOption('05', 'May'));
test_options.add(new SelectOption('06', 'Jun'));
test_options.add(new SelectOption('07', 'Jul'));
test_options.add(new SelectOption('08', 'Aug'));
test_options.add(new SelectOption('09', 'Sep'));
test_options.add(new SelectOption('10', 'Oct'));
test_options.add(new SelectOption('11', 'Nov'));
test_options.add(new SelectOption('12', 'Dec'));
Months my_months = new Months();
List<SelectOption> method_options = my_months.getMonthList();
system.assertEquals(method_options, test_options);
}
}
Dan,
I don't think assertEquals works with lists/arrays/etc only basic data types.
From the apex language reference doc the arguments types are AnyDataType (which I think is just String, Boolean etc).
My best practice on testing what you have would be make sure both lists are the same size (fail if not) and then loop checking the nth element in each list misc element against each other
IE (not real code of course)
//start of test
system.assertEquals(method_options.size(), test_options.size());
if( method_options.size() == test_options.size() ){
//do a for loop
//in loop assert each data element in the select option equals the other
Sorry would have offered more but should be enough to get you started.
All Answers
Dan,
I don't think assertEquals works with lists/arrays/etc only basic data types.
From the apex language reference doc the arguments types are AnyDataType (which I think is just String, Boolean etc).
My best practice on testing what you have would be make sure both lists are the same size (fail if not) and then loop checking the nth element in each list misc element against each other
IE (not real code of course)
//start of test
system.assertEquals(method_options.size(), test_options.size());
if( method_options.size() == test_options.size() ){
//do a for loop
//in loop assert each data element in the select option equals the other
Sorry would have offered more but should be enough to get you started.
That was exactly what I needed, thanks for push in the right direction!
Sincerely,
Dan