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

Test method for a custom component
Hi, can someone help me write the test method for the following custom component. I couldnt find any link to custom component test methods in the force.com knowledgebase/community. Please help.
public with sharing class AutoComplete_Controller{ //Constructors public AutoComplete_Controller() {} public AutoComplete_Controller(ApexPages.StandardController controller) {} //Attributes private List<String> resultsname = new List<String>(); private Boolean hasparams = false; private Boolean hasnoresults = false; public String state = ''; //Getters and Setters public Boolean getHasparams(){ return hasparams; } public void clearValues(){ hasparams = false; } public Boolean getHasnoresults(){ return hasnoresults; } public void avoidRefresh(){ } /*public void setState(String sName) { state = sName; system.debug('sName - ' + sName); } public String getState() { return state; }*/ public PageReference searchSuggestions() { //Initalize variables, hasparams just indicates that a search has started resultsname.clear(); hasparams = true; hasnoresults = false; //Obtain current parameters String sobjectname = System.currentPageReference().getParameters().get('objectname'); String stext = String.escapeSingleQuotes(System.currentPageReference().getParameters().get('aname').trim())+'%'; String stateText = String.escapeSingleQuotes(System.currentPageReference().getParameters().get('statename').trim()); system.debug('State Name - ' + state); system.debug('stateText - ' + stateText); //Limit Suggestions to 10 Results Integer iLimit = 10; //Validate if there's an input and get results if(stext.length() > 2){ try{ //String sql = 'select City__C from ' + sobjectname + ' where City__C like \''+stext+'\' and State__c = ' + stateText + '' limit '+ iLimit; String sql = 'select City__C from ' + sobjectname + ' where City__C like \'' + stext + '\' and State__c = \''+ stateText+'\' GROUP BY City__C'; // limit ' + iLimit; //lstAR = []; system.debug('SQL Formed + ' + sql ); // for(sobject x : Database.query(sql)){ String s = String.escapeSingleQuotes(((String)(x.get('City__C')))); resultsname.add(s); } }catch(Exception e){ resultsname.add('Unexpected Error, please contact support- '); } } return null; } public List<String> getResultsname(){ //Make sure to clear past values clearValues(); if(resultsname.isEmpty()){ hasnoresults = true; resultsname.add('No Results'); } return resultsname; } }
thank you
I think the reason you're having difficulty finding any links to help you out here is because you're searching for the wrong thing.
This is a controller extension, not a custom component.
Here's a good place to start:
http://salesforcesource.blogspot.com/2008/09/testing-your-controller-extentions.html
But I am using this controller in the component , and here is the code for the component