You need to sign in to do that
Don't have an account?
Frank Carter
test class: wrapper class increase code coverage
Hello I have this apex class and I tried to write a good test class. I obtain a 78% code coverage but I want to know what is missing and what I have to do to improve it and to improve my skills on test class.
apex class:
Test class:
Thanks
apex class:
public class SearchWithWrapperC { public Date StartDate {get;set;} public Date EndDate {get;set;} public List<WrapperClass> listBD {get;set;} public void loadData() { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,SF_Opportunity_Id__c,Account_Name__c,Billing_Detail__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Billing_Status__c='Authorized for Billing'AND Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate Order by Account_Name__c, Monthly_Forecast__c]){ listBD.add(new WrapperClass (cr, false)); } } public List<WrapperClass> getBilling() { if(listBD == null) { listBD = new List<WrapperClass>(); for(Billing_Detail__c cr : [Select Id,SF_Opportunity_Id__c,Account_Name__c,Billing_Detail__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c from Billing_Detail__c Where Billing_Status__c='Authorized for Billing'AND Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate Order by Monthly_Forecast__c ]){ listBD.add(new WrapperClass (cr, false)); } } return listBD; } public PageReference processSelected() { Integer m = Date.Today().Month(); List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>(); for(WrapperClass bd: getBilling()){ if(bd.check_box== true){ selectedBD.add(bd.cs); } } for(Billing_Detail__c cs: selectedBD) { cs.Monthly_Forecast__c = Date.newinstance( cs.Monthly_Forecast__c.year() , m , cs.Monthly_Forecast__c.day() ); update selectedBD; System.debug('The value is: ' + cs.Monthly_Forecast__c ); } return null; } public class WrapperClass { public Billing_Detail__c cs {get; set;} public Boolean check_box {get; set;} public WrapperClass(Billing_Detail__c c, Boolean check_box){ this.cs = c; this.check_box = false; } } }
Test class:
@isTest private class SearchWithWrapperCTest { @isTest static void testController() { Test.startTest(); // create the object in input of the class Account a= new Account(); a.name='Account test t'; a.RecordTypeId='012w0000000iROM'; a.Branch__c='Italy'; a.Status__c='Customer'; a.BillingCountry='Italy'; a.Public_Administration_Account__c='No'; insert a; Opportunity testOpportunity = new Opportunity( AccountID = a.Id, Name = 'Test Opportunity', StageName = 'Needs Analysis', CloseDate = date.today().addDays(15) ); insert testOpportunity; Billing_Detail__c c= new Billing_Detail__c(); c.Amount__c= 100; c.Billing_Type__c='FEE'; c.Billing_Period__c='monthly'; c.Billing_Status__c='Authorized for Billing'; c.Product_Line__c='Interactive Experience (iX)'; c.Product__c='Chat Delivery'; c.Monthly_Forecast__c=Date.newInstance(2018, 7, 9); c.End_of_Billing__c=Date.newInstance(2019, 7, 9); c.Billing_Detail__c=testOpportunity.Id; insert c; Date StartDate= Date.newInstance( 2018, 10,1); Date EndDate= Date.newInstance( 2018,10,18 ); list<WrapperClassTest> wrp= new list<WrapperClassTest>(); ApexPages.StandardController sc = new ApexPages.StandardController(c); SearchWithWrapperC x =new SearchWithWrapperC(); x.loadData(); x.getBilling(); for(WrapperClassTest wTest :wrp) { wTest.check_box=true; } x.processSelected(); System.assert(wrp.size() > 1); Test.stopTest(); } Public class WrapperClassTest{ public Billing_Detail__c cs {get;set;} public Boolean check_box {get;set;} public WrapperClassTest(Billing_Detail__c c, Boolean check_box) { this.cs = c; this.check_box = false; } } }
Thanks
SearchWithWrapperCTest)What are the red lines? (post them)
All Answers
If you open your class with the developer console, there is a button "Code coverage All Test"
The red lines are not covered.
The blue lines are covered.
thanks for answering. on my developer console I Have none:
How to do to have all test?
Thanks
SearchWithWrapperCTest)What are the red lines? (post them)