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
Admin User 8209Admin User 8209 

code coverage 0 %

my controller class

public class AbSearchInVFController {
    public list <AddressBook__c> address {get;set;}
   public String searchKey {get;set;}
    public String blockKey {get;set;}
     public String areaKey {get;set;}
     public String buildingKey {get;set;}
       public Address add {get; set;}
     public Integer counter {get; set;}
     public AbSearchInVFController( ) {
    }
    public void search(){
        string searchquery='  select Name,Concerned_Person_Name__c,Company_Name__c ,Building_Name__c ,Location__c, Area_Occupied__c,'+
        'Block__c,Floor__c,Plot_Area__c,City__c,Unit_No__c,Concerned_Person_mobile__c,Remarks_By_Support_Staff__c,Remarks_By_Surveyor__c, State__c ,Createddate,CreatedById, OwnerId,lastModifiedById'+ 
        'from AddressBook__c'+
        'where  Location__c  like \'%'+searchkey+'%\''+
        'and Plot_Area__c like \'%'+areaKey+'%\''+
        'and Building_Name__c like \'%'+buildingKey+'%\''+
        'and block__c like \'%'+blockKey+'%\' Limit 100';
        address=Database.query(searchquery);
    } 
       public void clear(){
        address.clear();
    }
   
}



Test class.

@istest
public class AbSearchInVFControllerlTest{

   public static TestMethod void Test(){
    {
    Test.startTest();
     AddressBook__c  testaddress = new  AddressBook__c  (); 
     
    
     testaddress.Unit_No__c ='1';
        testaddress.Block__c ='A';
         testaddress.Concerned_Person_mobile__c ='9910008084';
            testaddress.Concerned_Person_Name__c ='mohan';
            testaddress.Floor__c ='1';
              testaddress.Building_Name__c ='buniyadt';
                testaddress.Company_Name__c ='bun';
                  testaddress.State__c='up';
                     testaddress.Location__c='18 sector';
                        testaddress.Area_Occupied__c='1000';
                           testaddress.City__c='Noida';
                           testaddress.Remarks_By_Support_Staff__c='Test';
                            testaddress.Remarks_By_Surveyor__c='Test';
                                           insert testaddress;
        
         
       ApexPages.StandardController controller = new ApexPages.StandardController(testaddress);
       
      Test.stopTest() ;     

    }
}
}

when i am deploing getting 0 % coverage 
Suraj Tripathi 47Suraj Tripathi 47

Hi,

Please find the solution.

@isTest
public class AbSearchInVFControllerTest{

public static testMethod void searchTest(){
 AbSearchInVFController.searchKey='Delhi';
  AbSearchInVFController.areaKey ='New';
   AbSearchInVFController.buildingKey ='Mannat';
    AbSearchInVFController.blockKey ='A';
	 /*if these all varaibles are not accessed in this test class then make your variable as static
      like public static String searchKey {get;set;}*/
 
   AddressBook__c obj=new AddressBook__c();
   obj.Location__c='Delhi';
   obj.Plot_Area__c ='New';
   obj.Building_Name__c ='Mannat';
   obj.block__c ='A';
   
   //Insert All required Fileds
   
   insert obj;
   address=new List<AddressBook__c>();
   address.add(obj);
   
    AbSearchInVFController.address  ='A';
   
	 Test.startTest();
     AbSearchInVFController.search();
	 AbSearchInVFController.clear();
     Test.stopTest();

	 
}
}


Please do some needful changes according to your code.

Please mark it as the Best Answer if it helps you.

Thank You