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

Test method for get set
Hi, I am trying to write a test method fo rthe following. I am a total newbie when it comes to code, so need lots of help, please.
public with sharing class accsearchcontroller {
public list <account> acc {get;set;}
public string searchstring {get;set;}
public accsearchcontroller(ApexPages.StandardController controller) {
}
public void search(){
string searchquery='select OwnerName__c,name,owner.phone,Account_Manager__c,BDM__c,BillingState,BillingCity, id from account where (name like \'%'+searchstring+'%\' OR OwnerName__c like \'%'+searchstring+'%\') Limit 1000';
acc= Database.query(searchquery);
}
public void clear(){
acc.clear();
}
}
Here is what i wrote, but gets an error, Error: Compile Error: Constructor not defined: [accsearchcontroller].<Constructor>() :
@isTest
public class accsearchcontrollerTest{
static testMethod void test() {
accsearchcontroller acc = new accsearchcontroller();
Test.startTest();
account[] accounts = acc.getAccounts();
Test.stopTest();
System.assertNotEquals(null, accounts);
}
}
Please advise, thanks!!!!!
public with sharing class accsearchcontroller {
public list <account> acc {get;set;}
public string searchstring {get;set;}
public accsearchcontroller(ApexPages.StandardController controller) {
}
public void search(){
string searchquery='select OwnerName__c,name,owner.phone,Account_Manager__c,BDM__c,BillingState,BillingCity, id from account where (name like \'%'+searchstring+'%\' OR OwnerName__c like \'%'+searchstring+'%\') Limit 1000';
acc= Database.query(searchquery);
}
public void clear(){
acc.clear();
}
}
Here is what i wrote, but gets an error, Error: Compile Error: Constructor not defined: [accsearchcontroller].<Constructor>() :
@isTest
public class accsearchcontrollerTest{
static testMethod void test() {
accsearchcontroller acc = new accsearchcontroller();
Test.startTest();
account[] accounts = acc.getAccounts();
Test.stopTest();
System.assertNotEquals(null, accounts);
}
}
Please advise, thanks!!!!!
http://salesforce.stackexchange.com/questions/40901/visualforce-controller-unit-test-vf-page-displays-fullcalendar
In your test, instantiate your controller, then call ctrl.search(); ctrl.clear();
Try the below code.
Use below code