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
HitHit 

How to write test case for Apex class?

Hello,

 

Can anyone help me to write a test case for the following method of the class?

I already create a test method but it only cover a 69%.

 

 

 

public static void smeExpertCompetencyRequirements(List<String> parentIdsList)
    {
    
   Integer apss;
 Integer acss;
 Integer acs;
 Integer acis;
 Integer pasmi;
 Integer j;
 Integer i;
 List<Individual_Cert_Product_Auth_Status__c> lstCert = [Select i.Id, i.Contact_Name__c,i.Expiration_Date__c, i.Certification_Code__c, i.Account__c From Individual_Cert_Product_Auth_Status__c i WHERE i.Account__c in :parentIdsList and i.Expiration_Date__c >: Date.today() ];
     List<Account> accList=[select id,Location_Type__c,SME_Expert_Competency__c from Account where id in :parentIdsList];
 for( j=0;j<accList.size();j++)  
 {
 apss =0;
 acss =0;
 acs=0;
 acis=0;
 pasmi=0;
 for(i=0; i < lstCert.size() - 1; i++) 
 {
 if(accList[i].id==lstCert[i].Account__c && lstCert[i].Certification_Code__c == 'APSS-1000'){
 apss++;
 }
 if(accList[i].id==lstCert[i].Account__c && lstCert[i].Certification_Code__c == 'ACSS-3000') {
 acss++;
 
if(accList[i].id==lstCert[i].Account__c && lstCert[i].Certification_Code__c == 'ACS-906') {
acs++;
}
if(accList[i].id==lstCert[i].Account__c && lstCert[i].Certification_Code__c == 'ACIS-6401') {
acis++;
}
if(accList[i].id==lstCert[i].Account__c && lstCert[i].Certification_Code__c == 'PASMI-102') {
pasmi++;
}
}
if(accList[i].Location_Type__c == 'Headquarters') 
{
if((apss >=2 && acss >=2) || (acs >=2) || (acss >=1 && acs >=1) || (acss >=1 || acs >=1) && (acis >=1 || pasmi >=1)) 
{
accList[i].SME_Expert_Competency__c = true;
}
else 
{
accList[i].SME_Expert_Competency__c = false;
}
}
}
update accList;
    }
}

 

 

Thanks,

Hit

r_boyd_848r_boyd_848

Assuming you're using the IDE start by looking at thelines that aren't being callled. Run the tests then expand the test results list. You have 8 if statements so make sure your tests cover each of the Cert Codes you're checking and you that the final IF covers all the OR scenarios.