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
dho1dho1 

Test Class and VisualForce Command Button

Hi,

 

I wanted to write test for my controller class for a visualforce page.  I have 2 command buttons that calls methods from my controller class.  How do go about writing the test to cover the commandbutton actions?

 

TIA!

Subramani_SFDCSubramani_SFDC

can u post ur code here???

Subramani_SFDCSubramani_SFDC
@isTest
public class thecontrollerTests {

    public static testMethod void testMyController() {
       
// insert sample records here...

//code for pagereference if u r using pagereference
PageReference pageRef = Page.success; Test.setCurrentPage(pageRef); create object for constructor thecontroller controller = new thecontroller(); controller.setLastName('lastname'); controller.setFirstName('firstname'); controller.setCompany('acme'); controller.setEmail('firstlast@acme.com');

// code for testing cmd buttons save and cance controller.Save();
Controller.Cancel(); // Verify that the success page displays System.assertEquals('/apex/success', nextPage); Lead[] leads = [select id, email from lead where Company = 'acme']; System.assertEquals('firstlast@acme.com', leads[0].email); } }



Ask if u have further clarification.....