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
SFDC@ChennaiSFDC@Chennai 

How to cover the % level in Test class?

Hi I created test class and called save method through the reference(CustomObj__c co = new CustomObj__c(); co.save()), its covering only true part.

I need cover up the list creating/ inserting part, Please find the below image for your reference.

User-added image
Thanks
Anoop yadavAnoop yadav
Hi,

Can you Post your Controller and Test Class.
SFDC@ChennaiSFDC@Chennai
Public class MyClass{
public MyClass (ApexPages.StandardController stdController) {}
public PageReference save() {
 
List < Report__c > foreRevRep = [SELECT Amount__c, Month__c, opp_id__c FROM Report__c WHERE opp_id__c = : this.oppId];
if (foreRevRep != null && foreRevRep.size() > 0) {

  
List < Report__c > frList = new List < Report__c > ();
if (opp.Select_Month_Division__c == '6' || opp.Select_Month_Division__c == '12' || opp.Select_Month_Division__c == '18' || opp.Select_Month_Division__c == '24' || opp.Select_Month_Division__c == '30' || opp.Select_Month_Division__c == '36') {
Report__c frr = new Report__c();
frr.opp_id__c = opp.Id;
if (this.amount1 != null) {
frr. Month__c = this.month1;
frr. Amount__c = this.amount1;
frr.Flag__c = 1;
frList.add(frr);
}
}

}
}}

@isTest
Public class MyTestClass{
Static testMethod void testMethod1(){
MyClass mc = new MyClass(new ApexPages.StandardController(o));
mc.save();
}
}

Note : Bold part is not covering 
Anoop yadavAnoop yadav
Hi,

You have not written the Controller properly.

Check the below link for this.
http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm

And for test class try the below link.
https://developer.salesforce.com/forums?id=906F00000008y7QIAQ

If need more help, let me know.