function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Justin LJustin L 

Custom Controller Test Class error "Constructor not defined: [ControllerName].<Constructor>() at line # column #


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.
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.Whatid = '';
        insert testTask;
        Products_Cutting__c item = new Products_Cutting__c ();
        item.Cutting_ID__c =;
        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

            //ApexPages.currentPage().getParameters().put('id', String.valueOf(;
            //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', );
            pageRef.getParameters().put('Product_Code__c', '01tC0000004OvjpIAC');

            CuttingItemsShownController testTask1 = new CuttingItemsShownController(new ApexPages.StandardController(testTask));

            testCutting.add ();


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.
mukesh guptamukesh gupta
Hi Justin,

Please use below line
ApexPages.StandardSetController setCon = new ApexPages.StandardSetController(testTask); 
CuttingItemsShownController testTask1 = new CuttingItemsShownController(setCon);

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.