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
sona gaikwadsona gaikwad 

how to write test class for below methods

public void validateData() {
        
        Boolean isErrorLogACall = FALSE;
        Boolean isErrorFollowUpTask = FALSE;
        Boolean isErrorOpenTasks = FALSE;
        Boolean PropState;
        
        
        
         if(AccountInfo.PersonMobilePhone!=null && AccountInfo.PersonMobilePhone!='')
           {
              if(LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.PersonMobilePhone,AccountInfo.Id))
              {
              System.debug('Duplicate Mobile 1: ');
               AccountInfo.PersonMobilePhone.addError('Duplicate : '+AccountInfo.PersonMobilePhone);
               isError = TRUE;
                     return;
              }
           }    
           
          if(AccountInfo.Mobile_2__c !=null && AccountInfo.Mobile_2__c!='')
           {
              if(LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.Mobile_2__c ,AccountInfo.Id))
              {
               AccountInfo.Mobile_2__c.addError('Duplicate : '+AccountInfo.Mobile_2__c );
               isError = TRUE;
                     return;
              }
           }    
           
         
           
           
             if(AccountInfo.PersonEmail!=null &&AccountInfo.PersonEmail!='')
           {
              if(LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.PersonEmail,AccountInfo.Id))
              {
               AccountInfo.PersonEmail.addError('Duplicate : '+AccountInfo.PersonEmail);
               isError = TRUE;
                     return;
              }
           }       
        
        
        
        //JJ - 04/27/2016
        
        
        if(AccountInfo.City_Village__c != null && AccountInfo.City_Village__c != '')
        {
            List<Village_City__c> lstCityVill = new List<Village_City__c>();
            
            lstCityVill = HandlerClass.getVillageCityAutocomplete(AccountInfo.City_Village__c, '');
            
            //Case Sensitive Logic
            for(Village_City__c recTaluka :lstCityVill)
            {
                PropState = AccountInfo.City_Village__c.equals(recTaluka.Name);  
                if(PropState) break;                  
            }
            //Case Sensitive Logic - End.
                        
             if(lstCityVill.isEmpty())
             {
                    AccountInfo.City_Village__c.addError('This Communication City/Village value is not available.');
                    isError = true;
             }
             else if(PropState == FALSE)
             {
                AccountInfo.City_Village__c.addError('This Case Sensitive Communication City/Village value is not available.');
                isError = true;
             }
        }
    }    
Best Answer chosen by sona gaikwad
Raj VakatiRaj Vakati
try this code
 
@isTest
public class validateDataTEtsClass {
static testMethod void unitTestInsert() {
   
    Test.startTest();
 Account acc = new Account(name='Test Account');
 acc.PersonMobilePhone='12312312312';
 acc.Mobile_2__c ='12343543543'';
 acc.PersonEmail='raj@fmail.com';
 acc.City_Village__c ='Bangalore';
 
          insert acc;

 
 YOURClass c = new YoutClass(); 
 c.validateData();
 
    Test.stopTest();      
}
}

 

All Answers

Raj VakatiRaj Vakati
try this code
 
@isTest
public class validateDataTEtsClass {
static testMethod void unitTestInsert() {
   
    Test.startTest();
 Account acc = new Account(name='Test Account');
 acc.PersonMobilePhone='12312312312';
 acc.Mobile_2__c ='12343543543'';
 acc.PersonEmail='raj@fmail.com';
 acc.City_Village__c ='Bangalore';
 
          insert acc;

 
 YOURClass c = new YoutClass(); 
 c.validateData();
 
    Test.stopTest();      
}
}

 
This was selected as the best answer
edanna kedanna k
Dear sona gaikwad,

Please find the below test method for your above method validateData()
static testMethod void validateDataTest() {
		 Account AccountInfo = new Account(Name = 'TestAcc1',PersonMobilePhone = '1234', Mobile_2__c = '4321', PersonEmail = 'test@mail.com', City_Village__c = 'cVill');
		 insert AccountInfo;
		 
		 Test.startTest();
		 Boolean b1 = LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.PersonMobilePhone, AccountInfo.id);
		 Boolean b2 = LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.Mobile_2__c, AccountInfo.id);
		 Boolean b3 = LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.PersonEmail, AccountInfo.id);
		 List<Village_City__c> lstCityVill = HandlerClass.getVillageCityAutocomplete(AccountInfo.City_Village__c, '');		 
		 yourClassName ycn = yourClassName();
		 ycn.validateData();
		 Test.stopTest();
	}
Please let me know if it helps!