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
mansimansi 

Test class urgent help!!

Hi can any one tell me how to cover the below code in the test class..

Class name is SaveOnEditAmexCampaignCtrlrExt 

only first few lines of my below code are covered.. please tellme  how to cover the whole method

 

       }

Best Answer chosen by Admin (Salesforce Developers) 
mansimansi

hey i think i have done all the three points that you mentioned. please have a look at my test class and tell me how can i increase the coverage of that method.

 

 

All Answers

IspitaIspita

Hi Mansi,

The job of test is to transverse each line of your code to provide adequate coverage. 

So basically in your test class you need to create date which will pass through each if /else clause of your code.

 

Though the exact cause analysis can be done if one goes through the code.

Yes it may happen that:-

  • There is an error in your code ~ run all tests and check the logs to see if any error has been encountered.
  • Also it might so happenthat your new code has added for conditional code with if-else and due to some reason some of the else or if statememts are not getting covered. 
  • You might have implemented condition for which you havent generated code or not created data to give due coverage.
  • The condition might be such that some conditions cannot be logically covered in the organizatgion's scenario.

 So in case the problem persists do share the test method which you have written so a proper analysis can be done.

 

mansimansi

thanks, but it is not going beyond the if statement only... and i have no idea how to do that

mansimansi

As far as i think it might be because of the new code that i have added in my previous code of the same class.. i have simply called the method using an instance of the class but it stops at the if statement. please tell me how to increase the full coverage

UVUV

Hi Mansi,

 

You have not posted complete code so I am not able to get how you are putting values in your wrapper list.However,

before calling the fetchOffersForTheSelecetdMerchants() method from the test class you need to make sure that-

1-accountWrapperList containts few values.So, add them from your test clas or if you have defined logic in your controller class then call that logic first.

2- Make sure wrapper list have few values checked(checkbox field must be true for few of them)

3-Make sure 'se' variable is not null or empty..

 

Above steps will cover the for loop you are having and "offerMer" list will have few values.

Few next lines depends on "offerMer" list so you must have values in it to cover code.

"lstOffers" is a collection of records you are getting from query so make sure you are getting records as next lines are dependent on this list..In this way go ahead and you would be able to cover the code...

mansimansi

hey i think i have done all the three points that you mentioned. please have a look at my test class and tell me how can i increase the coverage of that method.

 

 

This was selected as the best answer
UVUV

hey, you are calling lot of methods before making a call to fetchOffersForTheSelecetdMerchants().

I guess values of wrapper list are getting changed by other calls..Would be great if you debug the wrapper list after each call in your test class..this is the way you can find out whether you are able to fulfill the conditions or not.