You need to sign in to do that
Don't have an account?
Custom Controller Test Class error "Constructor not defined: [ControllerName].<Constructor>() at line # column #
Hello,
Yet another admin getting over their head in a foray into Apex. I wrote a visualforce page (Cutting_ItemsShown) that required a custom controller (CuttingItemsShownController). The VF page displays a list of associated records to the Task based on the Cutting_ID__c field on the Products_Cutting__c object. These two parts work well, the trouble comes when trying to write a test class for the controller.
The error received is as in the title:
Error: Compile Error: Constructor not defined: [CuttingItemsShownController].<Constructor>() at line 47 column 53
I'm thinking this has to do with the fact I'm displaying a list, but I'm not sure how to resolve it. Is there any direction or resources you can provide to help me better understand the problem and the solution? Thank you.
Yet another admin getting over their head in a foray into Apex. I wrote a visualforce page (Cutting_ItemsShown) that required a custom controller (CuttingItemsShownController). The VF page displays a list of associated records to the Task based on the Cutting_ID__c field on the Products_Cutting__c object. These two parts work well, the trouble comes when trying to write a test class for the controller.
@isTest public class CuttingItemsShownControllerTest { static testMethod void testMethod1() { Account testAccount = new Account(); testAccount.Name = 'Test Account'; insert testAccount; Task testTask = new Task(); testTask.RecordTypeId='0120y000000IBKkAAO' ; testTask.Subject='Cutting'; testTask.Who_did_we_cut_against__c='Competitor'; testTask.Did_We_Win__c='Yes'; testTask.Whatid = 'testAccount.id'; insert testTask; Products_Cutting__c item = new Products_Cutting__c (); item.Cutting_ID__c = testTask.id; item.Product_Code__c = '01tC0000004OvjpIAC'; item.Name = 'SKUCode'; item.Flavor__c = 'Company'; item.Yield__c = 'Company'; item.External_Texture__c = 'Company'; item.Internal_Texture__c = 'Company'; item.Cooked_Color__c = 'Company'; item.Hold_Time__c = 'Company'; item.Length__c = 'Company'; item.Defects_Appearance__c = 'Company'; item.Competitor_Item__c = '1234567901234'; item.account_name__c = testAccount.Name; insert item; contract contr = new contract(); // add all required field Test.StartTest(); //ApexPages.currentPage().getParameters().put('id', String.valueOf(testTask.id)); //CuttingItemsShownController test = new CuttingItemsShownController(ApexPages.StandardController(testTask)); //ApexPages.StandardController sc = new ApexPages.StandardController(item); //CuttingItemsShownController testCutting = new CuttingItemsShownController(ApexPages.CuttingItemsShownController(testTask)); PageReference pageRef = Page.Cutting_ItemsShown; pageRef.getParameters().put('Cutting_Id__c', testTask.id ); pageRef.getParameters().put('Product_Code__c', '01tC0000004OvjpIAC'); Test.setCurrentPage(pageRef); CuttingItemsShownController testTask1 = new CuttingItemsShownController(new ApexPages.StandardController(testTask)); testTask.redirPage(); Test.StopTest(); testCutting.cancel(); testCutting.add (); Test.StopTest(); } }
The error received is as in the title:
Error: Compile Error: Constructor not defined: [CuttingItemsShownController].<Constructor>() at line 47 column 53
I'm thinking this has to do with the fact I'm displaying a list, but I'm not sure how to resolve it. Is there any direction or resources you can provide to help me better understand the problem and the solution? Thank you.
Please use below line
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh