Activity Forums Salesforce® Discussions How can we do build test class for the pagereference method?

  • How can we do build test class for the pagereference method?

    Posted by Mohit on August 16, 2016 at 2:42 pm

    Hi All,

    How can we do build test class for the pagereference method?

    In this scenario we want that to built a test class for the pagereference method.

    Please give suggestions.

    • This discussion was modified 8 years, 3 months ago by  Mohit.
    • This discussion was modified 8 years, 2 months ago by  Forcetalks.
    Surbhi replied 8 years, 2 months ago 2 Members · 1 Reply
  • 1 Reply
  • Surbhi

    Member
    August 26, 2016 at 3:46 pm

    Hi Mohit,

    You can refer to below code:

    @isTest
    private class testMyController{

    private static testMethod void testAutoRun() {

    test.startTest();
    PageReference pageRef = Page.yourPageName;
    Account acc = new Account(Name='Abce');
    insert acc;
    Opportunity testOppty = new Opportunity();
    testOppty.name='testOppty';
    testOppty.AccountId=acc.id;
    testOppty.StageName='Open';
    testOppty.CloseDate=System.today();
    insert testOppty;
    Test.setCurrentPage(pageRef);
    pageRef.getParameters().put('id',testOppty.id);
    ApexPages.StandardController sc = new ApexPages.standardController(testOppty);
    Myclass controller = new Myclass(sc);
    System.assertNotEquals(null,controller.autoRun());

    test.stopTest();
    }

    }

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos