0

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

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)
                       { 

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;

  • does the query return any rows? does it return a row where the first "if" would be true? Note you need to mock test data in your test class for the code being tested to actually find the rows – cropredy Mar 8 '15 at 19:56
-1

Use the following piece of code

if (SalesAccreditationName==SalesCertName || Test.isRunningTest())
               {
                 if (TechAccreditationName==TechCertName || Test.isRunningTest() || Test.isRunningTest()) 
                 {

        if (SalesAccredCertCount==SalesCertCount || Test.isRunningTest())
                    {

                       if (TechAccredCertCount==TechCertCount || Test.isRunningTest())
                       { 
  • Sorry for the downvote, but this solution does not result in meaningful code coverage. The lines will be "covered" in that they will be processed, but this does not test any actual business case or "real world situation". Instead, follow crop1645's advice and create test data that meets the conditions of your IF statements, and make sure that said results are returned in the MyPLCLst query. – Matt Britton Mar 9 '15 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.