You need to sign in to do that
Don't have an account?
zimmerpk
Testing a Controller - Method does not exist
I am writing my first controller test and running into an issue. The controller is used to drive a custom keystroke in the service console.
Here is the controller:
public class ShortcutListenerController { // Lead id for lead to be closed public String selectedObjectId {get; set;} public String closeReason {get; set;} // Close Lead public PageReference closeLead() { system.debug('The Lead Id is :'+ selectedObjectId); system.debug('The Reason is :'+ closeReason); Lead selectedLead = [SELECT id, status, Lead_Status_If_Closed_Specify__c FROM Lead WHERE id =:selectedObjectId LIMIT 1]; selectedLead.status = 'Closed'; selectedLead.Lead_Status_If_Closed_Specify__c=closeReason; update selectedLead; return null; } }
Here is my test script:
@isTest public class ShortcutControllerTest { ShortcutListenerController controller = new ShortcutListenerController(); public static testMethod void shortcuttest() { // create lead Lead tl = new Lead( LastName = '123456', Company= '654321', Phone='1233213222'); insert tl; system.debug('Lead ID ='+tl.id); ApexPages.currentPage().getParameters().put('selectedObjectId', tl.id); ApexPages.currentPage().getParameters().put('closeReason', 'Test'); PageReference pr = controller.closeLead(); Lead t2 =[SELECT id, status, Lead_Status_If_Closed_Specify__c FROM Lead WHERE id =:tl.id]; system.debug('Close Reason ='+t2.Lead_Status_If_Closed_Specify__c); system.debug('Status ='+t2.status); } }
Why am I getting the error "Method does not exist of incorrect signature: controller.closeLead();
Thanks in advance
Phil
Hi,
Try move your class instantiation inside the test method:
-Hengky-
All Answers
Hi
Just taking a stab, but try making controller public, or within the scope of shortcuttest.
Oh, and I have no idea if "controller" is a keyword, but you might want to rename it to something that doesn't mean something so critical -- you know, like "testcon" pr something like that.
Hi,
Try move your class instantiation inside the test method:
-Hengky-