Skip to main content
added 785 characters in body
Source Link
Priya
  • 115
  • 1
  • 3
  • 6

The above values are returned from queries which I loop thro using for loop.

This is how I set values and call batch class.

Yet that 6 lines are not covered.

Aacb.SalesCertName = 'Sales Certified For Enterprise service solutions'; Aacb.TechCertName = 'Technical Certified For Enterprise service solutions'; Aacb.SalesAccreditationName = 'Sales Certified For Enterprise service solutions'; Aacb.TechAccreditationName = 'Technical Certified For Enterprise service solutions'; Aacb.SalesAccredCertCount = 5; Aacb.TechAccredCertCount = 3; Aacb.SalesCertCount = 5; Aacb.TechCertCount = 3; Aacb.RevCount = 34000; acc.CQ_Consolidated_Revenue__c = 34000;

The above values are returned from queries which I loop thro using for loop.

This is how I set values and call batch class.

Yet that 6 lines are not covered.

Aacb.SalesCertName = 'Sales Certified For Enterprise service solutions'; Aacb.TechCertName = 'Technical Certified For Enterprise service solutions'; Aacb.SalesAccreditationName = 'Sales Certified For Enterprise service solutions'; Aacb.TechAccreditationName = 'Technical Certified For Enterprise service solutions'; Aacb.SalesAccredCertCount = 5; Aacb.TechAccredCertCount = 3; Aacb.SalesCertCount = 5; Aacb.TechCertCount = 3; Aacb.RevCount = 34000; acc.CQ_Consolidated_Revenue__c = 34000;

added 3202 characters in body
Source Link
Priya
  • 115
  • 1
  • 3
  • 6

Hi,

Here goes further explanation.

 List<Partner_Level_Criterias__c> MyPLCLst   = [select Sales_Certification_Name__c,Technical_Certification_Name__c,Sales_Certification_Count__c,Technical_Certification_Count__c  from PartnerLevel__c ];  

for (PartnerLevel__c p : MyPLCLst )
            { 
                                  
                  SalesCertName     = String.valueOf(p.Sales_Certification_Name__c);
                  TechCertName      = String.valueOf(p.Technical_Certification_Name__c);
            
                   if (AccreditationName==SalesCertName)
                   {
            
         
                     SalesCertCount    = Integer.valueOf(p.Sales_Certification_Count__c);
                     SalesAccreditationName  = AccreditationName;        
                
                                   
                                   
                    }  //  end if (AccreditationName==SalesCertName)
            
           
            
                  if (AccreditationName==TechCertName)
                   {
            
                     TechCertCount    = Integer.valueOf(p.Technical_Certification_Count__c);
                     TechAccreditationName  = AccreditationName;   
                                       
                 
            
                    }  // end if (AccreditationName==TechCertName)
                        
             } // end of for MyPLCLst

if (SalesCertName!=NULL && TechCertName!=NULL && SalesAccreditationName!=NULL && TechAccreditationName!=NULL) {

/**************** TILL THIS IT GETS CODE COVERAGE***************************/

/***************** THE LINES AFTER THIS SHOWS UP IN RED COLOR **************/

               if (SalesAccreditationName==SalesCertName)
               {
            
                 if (TechAccreditationName==TechCertName)
                 {

        if (SalesAccredCertCount==SalesCertCount)
                    {
             
                       if (TechAccredCertCount==TechCertCount)
                       { 

TEST CLASS CODE SNIPPET :

Here is the code snippet from test class where I call PartnerLevel__c

PartnerLevel__c pl=new PartnerLevel__c(Sales_Certification_ID__c=AccountAccr.ID,Sales_Certification_Count__c=5); insert pl;

PartnerLevel__c pl1=new PartnerLevel__c(Technical_Certification_ID__c=AccountAccr1.ID,Technical_Certification_Count__c=3); insert pl1;

Call to Batch Apex class.

How should I cover the following which is checked after the for (PartnerLevel__c p : MyPLCLst ) loop ends.

 if (SalesAccreditationName==SalesCertName)
               {
            
                 if (TechAccreditationName==TechCertName)
                 {

        if (SalesAccredCertCount==SalesCertCount)
                    {
             
                       if (TechAccredCertCount==TechCertCount)
                       { 

Hi,

Here goes further explanation.

 List<Partner_Level_Criterias__c> MyPLCLst   = [select Sales_Certification_Name__c,Technical_Certification_Name__c,Sales_Certification_Count__c,Technical_Certification_Count__c  from PartnerLevel__c ];  

for (PartnerLevel__c p : MyPLCLst )
            { 
                                  
                  SalesCertName     = String.valueOf(p.Sales_Certification_Name__c);
                  TechCertName      = String.valueOf(p.Technical_Certification_Name__c);
            
                   if (AccreditationName==SalesCertName)
                   {
            
         
                     SalesCertCount    = Integer.valueOf(p.Sales_Certification_Count__c);
                     SalesAccreditationName  = AccreditationName;        
                
                                   
                                   
                    }  //  end if (AccreditationName==SalesCertName)
            
           
            
                  if (AccreditationName==TechCertName)
                   {
            
                     TechCertCount    = Integer.valueOf(p.Technical_Certification_Count__c);
                     TechAccreditationName  = AccreditationName;   
                                       
                 
            
                    }  // end if (AccreditationName==TechCertName)
                        
             } // end of for MyPLCLst

if (SalesCertName!=NULL && TechCertName!=NULL && SalesAccreditationName!=NULL && TechAccreditationName!=NULL) {

/**************** TILL THIS IT GETS CODE COVERAGE***************************/

/***************** THE LINES AFTER THIS SHOWS UP IN RED COLOR **************/

               if (SalesAccreditationName==SalesCertName)
               {
            
                 if (TechAccreditationName==TechCertName)
                 {

        if (SalesAccredCertCount==SalesCertCount)
                    {
             
                       if (TechAccredCertCount==TechCertCount)
                       { 

TEST CLASS CODE SNIPPET :

Here is the code snippet from test class where I call PartnerLevel__c

PartnerLevel__c pl=new PartnerLevel__c(Sales_Certification_ID__c=AccountAccr.ID,Sales_Certification_Count__c=5); insert pl;

PartnerLevel__c pl1=new PartnerLevel__c(Technical_Certification_ID__c=AccountAccr1.ID,Technical_Certification_Count__c=3); insert pl1;

Call to Batch Apex class.

How should I cover the following which is checked after the for (PartnerLevel__c p : MyPLCLst ) loop ends.

 if (SalesAccreditationName==SalesCertName)
               {
            
                 if (TechAccreditationName==TechCertName)
                 {

        if (SalesAccredCertCount==SalesCertCount)
                    {
             
                       if (TechAccredCertCount==TechCertCount)
                       { 
Source Link
Priya
  • 115
  • 1
  • 3
  • 6

Test Coverage for Batch Apex

Im getting a test coverage of 79%. I need 100% coverage.

It use 2 queries as lists and take data from it by cmparing. Most of them was covered.

I pass values to the 2 objects from test class.

Per developer console, Im not able to cover for the following statements.

 if (SalesAccreditationName==SalesCertName)
               {
            
                 if (TechAccreditationName==TechCertName)
                 {
             
                    if (SalesAccredCertCount==SalesCertCount)
                    {
             
                       if (TechAccredCertCount==TechCertCount)
                       { 

etc.

These variable are set inside the for loop of list of a query.The check happens after the for loop brackets are closed.

Is that the problem ? If the variable checks are inside the for loop whose values are set ,it would have been covered automatically is it ?

Please advice.

Thanks, Priya