Skip to main content
Demo Directsync perguntou em #Apex
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
2 respostas
  1. 6 de nov. de 2015, 05:04
    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
0/9000