Skip to main content
Lindsey Colvin が「#Apex」で質問
Hi,

I am fairly new to developing classes and pages, and need assistance in getting a test class to work for this controller extension.  Your help is appreciated!

Controller:

public with sharing class OpportunityControllerExtension {

    private final Opportunity opp;

    

        public OpportunityControllerExtension(ApexPages.StandardController stdController)  {

            this.opp = (Opportunity) stdController.getRecord();

            

       }

       

    public PageReference Dismiss()  {

    

        opp.Display_Alert__c = false;

        update opp;

        

            PageReference pageRef = ApexPages.currentPage();

            pageRef.setRedirect(true);

            return pageRef;

            

            

       }

   }

I've tried a simple insert new opportunity test class, but I keep getting the error "Error: Compile Error: Constructor not defined".

Thank you!
2 件の回答
  1. 2016年7月22日 16:38

    @isTest

    public class testOpportunityControllerExtension

    {

    static testMethod void test()

    {

    PageReference pageRef = Page.<your visualforce page name>;

    Test.setCurrentPage(pageRef);

    Account testAcct = new Account (Name = 'My Test Account');

    insert testAcct;

    // Creates first opportunity

    Opportunity oppt = new Opportunity(Name ='New mAWS Deal',

    AccountID = testAcct.ID,

    StageName = 'Customer Won',

    Amount = 3000,

    CloseDate = System.today(),

    Display_Alert__c=false);

    insert oppt;

    ApexPages.StandardController sc = new ApexPages.StandardController(Oppt);

    OpportunityControllerExtension testObj=new OpportunityControllerExtension(sc);

    Test.startTest();

    testObj.Dismiss();

    Test.stopTest();

    }

    }

    try this one.