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
vodnuravodnura 

Creating a test class

I am newbie to developing test cases. can anybody guide me in writing a test class for the following code.

 

 

public class MyController {
   public MyController(ApexPages.StandardController controller) { 
   
    }
    Lead lead1;
    public PageReference save() {   
       if (lead1.Company == 'Unknown')
              {
              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Do not Enter Uknown as Company Name'));
                return null;
            }  
        update lead1;        
        return null;
     }
    public String getName() {
        return 'MyController';
    }
    public Lead getLead() {
        if(lead1 == null) 
            lead1 = [select id,Company,Phone, name,Email,Notes__c,
                     Street,city,State,Availability_for_Call__c,
                      LeadSource
                     from Lead
                     where id = :ApexPages.currentPage().getParameters().get('id')];
        return lead1; 
    } 
}

 

 

Vishnu7700Vishnu7700

Create two lead and update the lead as below

@isTest
    public class exampleTest{

        static testMethod void test(){
            lead l1 = new lead(with appro lead feilds);

            insert l1;

            lead l2 = new lead(with appro lead feilds);

            insert l1;2

Test.StartTest();

update l1
Test.StopTest();

 }

}