+ Start a Discussion
Zabi MohammedZabi Mohammed 

Constructor not defined

Hi,
please  any body help on bellow error i am getting this error when i was writing a test class
Constructor not defined: [ApexPages.StandardController].<Constructor>(List<Account>)
Constructor not defined: [MyController].<Constructor>(ApexPages.StandardController)
i was use bellow code to solve this problem but still i am getting same error.
PageReference aPage = Page.aPage;
aPage.getParameters().put('AnyVariable', 'Test Value');
test.setCurrentPage(aPage);
 
// Instantiate the standard controller
Account act = new Account();
Apexpages.StandardController sc = new Apexpages.standardController(act);
 
// Instantiate the extension
myControllerExtension ext = new myControllerExtension(sc);
thanks,
zabi
James LoghryJames Loghry
Can you post the code for the MyControllerExtension class (and also the full test class)?  It looks like your test class is trying to call the incorrect constructor.  When you post the code, please use the code format (< >) button.
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for test class. I hope that will help you
http://amitsalesforce.blogspot.in/search/label/Test%20Class

Please check below post. How to write test classes
http://amitsalesforce.blogspot.in/2015/06/best-practice-for-test-classes-sample.html

Please check below Example how to create test class for trigger, Controller and Standard Controller.

Test Class for Trigger
@isTest 
public class TriggerTestClass 
{
    static testMethod void testMethod1() 
 {
  // Perform DML here only
 
        }
}
Test Class for Standard Controller
@isTest 
public class ExtensionTestClass 
{
 static testMethod void testMethod1() 
 {
 Account testAccount = new Account();
 testAccount.Name='Test Account' ;
 insert testAccount;

 Test.StartTest(); 
  ApexPages.StandardController sc = new ApexPages.StandardController(testAccount);
  myControllerExtension testAccPlan = new myControllerExtension(sc);

  PageReference pageRef = Page.AccountPlan; // Add your VF page Name here
  pageRef.getParameters().put('id', String.valueOf(testAccount.Id));
  Test.setCurrentPage(pageRef);

  //testAccPlan.save(); call all your function here
 Test.StopTest();
 }
}
Test Class for Controller class
@isTest 
public class ControllerTestClass 
{
 static testMethod void testMethod1() 
 {
 Account testAccount = new Account();
 testAccount.Name='Test Account' ;
 insert testAccount;

 Test.StartTest(); 

  PageReference pageRef = Page.AccountPlan; // Add your VF page Name here
  pageRef.getParameters().put('id', String.valueOf(testAccount.Id));
  Test.setCurrentPage(pageRef);

  myController testAccPlan = new myController();
  
  //testAccPlan.save(); call all your function here
 Test.StopTest();
 }
}

Please let us know if this will help you

Thanks
Amit Chaudhary