+ Start a Discussion
Rana RoyRana Roy 

Help required on Test Class

Developers,
Can you please help me to write the Test Class of the following Class?
public class LeadSearchController {
public Lead leadRecord {get; set;}
public List<Lead> leadList {get; set;}

public LeadSearchController(ApexPages.StandardController controller) {
leadRecord = new Lead();
leadList = new List<Lead>();
      }

public void getLeadData() {
if(leadRecord.Rating != null){
leadList = [SELECT Id, Name, Email, Rating FROM Lead WHERE Rating != null AND Rating =: leadRecord.Rating];
             }
      }
}

Thanks in advance
Best Answer chosen by Rana Roy
AshlekhAshlekh
Hi 
static testmethod void validateStandardController(){
       
        Lead l = new Lead(Firstname='test', lastName="test');
        insert l;
        PageReference pageRef = Page.YOUR_PAGE_Name;
        pageRef .getParameters().put('id',l.id)
        Test.setCurrentPage(pageRef);
       Test.StartTest();
        ApexPages.StandardController con = new ApexPages.StandardController(l); 
        LeadSearchController  Ls= new LeadSearchController(con);
        Ls.getLeadData();
        Test.StopTest();
      }

-Thanks
Ashlekh Gera

All Answers

AshlekhAshlekh
Hi 
static testmethod void validateStandardController(){
       
        Lead l = new Lead(Firstname='test', lastName="test');
        insert l;
        PageReference pageRef = Page.YOUR_PAGE_Name;
        pageRef .getParameters().put('id',l.id)
        Test.setCurrentPage(pageRef);
       Test.StartTest();
        ApexPages.StandardController con = new ApexPages.StandardController(l); 
        LeadSearchController  Ls= new LeadSearchController(con);
        Ls.getLeadData();
        Test.StopTest();
      }

-Thanks
Ashlekh Gera
This was selected as the best answer
Harish RamachandruniHarish Ramachandruni
@isTest
public class GSDAccountteammembercontrollerTest{
 
 
    private static testMethod void SaveRecordTest(){

for(integer i ; i<5 ; i++)
{
       Lead l1 = new Lead(Firstname='test', lastName="test' ,Rating = 'hot' );
        insert l1;


}

 Lead l = new Lead(Firstname='test', lastName="test' ,Rating = 'hot' ); 

insert l;

       
        
        ApexPages.StandardController con = new ApexPages.StandardController(l); 
        LeadSearchController  Ls= new LeadSearchController(con);
        Ls.getLeadData();
        Test.StopTest();
      }


}

Use this code u can get code coverage .


Regards ,
Harish.R
Rana RoyRana Roy
Your code is working great Ashlekh.
Harish, I am getting message:
User-added image
Thanks to both of you