+ Start a Discussion
SFDC Coder 8SFDC Coder 8 

Error in Test class Constructor not defined: [myClass].<Constructor>()

Hi All,
I am getting error in test class as constructor not defined.
Here is my code
 
@isTest
public class myClass_Test
{
public static testMethod void testMethod() {
        account acc = new account();
        acc.Name = 'test account';
        acc.F1__c='test';
       
        insert acc ;
        contact con=new contact();
        con.LastName=acc.F1__c;
     
        Obj1__c o = new Obj1__c ();
        o.F1__c = acc.Id;
        o.F2__c= con.LastName;
        
        
        insert o;
        
        
    PageReference myPage = Page.myPage;
    myPage.getParameters().put('id', o.Id);  
    Test.setCurrentPage(myPage);    
    ApexPages.StandardSetController control = new ApexPages.StandardSetcontroller(o);
    myClass pageControl = new myClass(control); 
     pageControl.bumpCases();
     pageControl.updateCases();   
     
    }

}
Controller Class
public with sharing class myClass 
{
    private ApexPages.StandardSetController standardController;

    public myClass(ApexPages.StandardSetController standardController)
    {
        this.standardController = standardController;
    }

    public PageReference bumpCases()
    {       
        // Get the selected records (optional, you can use getSelected to obtain ID's and do your own SOQL)
        List<Obj1__c> selectedCases = (List<Obj1__c>) standardController.getSelected();

        // Update records       
        for(obj1__c selectedCase : selectedCases)
        {
            if(selectedCase.status__c == 'Saved') 
                selectedCase.status__c = 'Cancelled';
            
        }       

        return null;        
    }

    public PageReference updateCases()
    {       
        // Call StandardSetController 'save' method to update (optional, you can use your own DML)
        return standardController.save();   
    }
}
Visualforce page
<apex:page standardController="obj1__c" extensions="myController" recordSetVar="Items" action="{!bumpCases}">
   <apex:form >
       <apex:pageBlock title="Bump Selected Items">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!updateCases}" value="Confirm"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!selected}" var="o">
                <apex:column value="{!o.status__c}"/>
                
            </apex:pageBlockTable> 
        </apex:pageBlock>
    </apex:form>    
</apex:page>

Please help me in this error
What change I need to do
Thanks in Advance
 
Best Answer chosen by SFDC Coder 8
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for test class example
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html

Please update your test class like below
@isTest
public class myClass_Test
{
	public static testMethod void testMethod1() 
	{
        account acc = new account();
        acc.Name = 'test account';
        acc.F1__c='test';
        insert acc ;
		
        contact con=new contact();
        con.LastName=acc.F1__c;

		List<Obj1__c> lstObj = new List<Obj1__c>();	
        Obj1__c o = new Obj1__c ();
        o.F1__c = acc.Id;
        o.F2__c= con.LastName;
        lstObj.add(0);

		insert lstObj;	
        
		PageReference myPage = Page.myPage;
		myPage.getParameters().put('id', o.Id);  
		Test.setCurrentPage(myPage);    
		ApexPages.StandardSetController control = new ApexPages.StandardSetcontroller(lstObj);
		control.setSelected(lstAccount);
		
		
		myClass ext = new myClass(control);
		
		pageControl.bumpCases();
		pageControl.updateCases();   
     
    }

}
Let us know if this will help you
 

All Answers

Dhruv Gour 14Dhruv Gour 14
I don't think this is the root cause of error . But you can try by renaming the testmethod name 

Thanks,
Dhruv
SFDC Coder 8SFDC Coder 8
Hi Dhruv,
I tired that, same error I am getting
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for test class example
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html

Please update your test class like below
@isTest
public class myClass_Test
{
	public static testMethod void testMethod1() 
	{
        account acc = new account();
        acc.Name = 'test account';
        acc.F1__c='test';
        insert acc ;
		
        contact con=new contact();
        con.LastName=acc.F1__c;

		List<Obj1__c> lstObj = new List<Obj1__c>();	
        Obj1__c o = new Obj1__c ();
        o.F1__c = acc.Id;
        o.F2__c= con.LastName;
        lstObj.add(0);

		insert lstObj;	
        
		PageReference myPage = Page.myPage;
		myPage.getParameters().put('id', o.Id);  
		Test.setCurrentPage(myPage);    
		ApexPages.StandardSetController control = new ApexPages.StandardSetcontroller(lstObj);
		control.setSelected(lstAccount);
		
		
		myClass ext = new myClass(control);
		
		pageControl.bumpCases();
		pageControl.updateCases();   
     
    }

}
Let us know if this will help you
 
This was selected as the best answer