You need to sign in to do that
Don't have an account?
Ronan O'Neill 6
How do I cover my SelectList<Options> in test class
I have a SelectList which is dynamically built from the controller. But it doesn't seem to get run in the Test Class. How can I make sure its covered?
My Test Class currently
public List<SelectOption> getCountyList() { List<SelectOption> options = new List<SelectOption>(); String counties = contactInfo[0].Preferred_Counties_for_Volunteering__c; if(!counties.contains(contactInfo[0].Home_County__c)) { options.add(new SelectOption(contactInfo[0].Home_County__c, contactInfo[0].Home_County__c)); } List<String> prefCounties = counties.split(';', -2); for(String pref : prefCounties) { options.add(new SelectOption(pref,pref)); } return options; }
My Test Class currently
@isTest public class ToTestFindNearby { static testMethod void testFindNearby () { PageReference pageRef = Page.FindNearby; Contact contact = new Contact (LastName = 'Test', Are_you_an_Engineer__c = 'Engineer', Home_County__c = 'Waterford' ); Account school = new Account (Name = 'Test', County__c = 'Waterford', Lat__c=5.0000, Lng__c=10.000, isMapped__c = true); //Test.startTest(); insert contact; insert school; system.assertEquals(true, school.isMapped__c); date myDate = date.newInstance(2015, 11, 21); School_Visit__c schoolVisit = new School_Visit__c (School__c = school.id, Status__c = 'Open for Volunteering', Topic__c = 'Science', How_many_students_in_the_class__c = 15, Requires_Irish_speaker__c = 'No', Preferred_Time__c = 'Afternoon', Date__c= myDate); School_Visit__c schoolVisit2 = new School_Visit__c (School__c = school.id, Status__c = 'Open for Volunteering', Topic__c = 'Engineering', How_many_students_in_the_class__c = 15, Requires_Irish_speaker__c = 'No', Preferred_Time__c = 'Afternoon'); School_Visit__c schoolVisit3 = new School_Visit__c (School__c = school.id, Status__c = 'Open for Volunteering', Topic__c = '', How_many_students_in_the_class__c = 15, Requires_Irish_speaker__c = 'No', Preferred_Time__c = 'Afternoon'); insert schoolVisit; insert schoolVisit2; insert schoolVisit3; //Test.stopTest(); pageRef.getParameters().put('id', contact.id); Test.setCurrentPage(pageRef); FindNearby controller = new FindNearby(); controller.backToContact(); } }
eg:
All Answers
eg:
Please try below code:-
Please mark this as best solution if this will help you.
Thanks
Amit Chaudhary
I kind of forgot it was a method cause it was all the way up in Variable country.