You need to sign in to do that
Don't have an account?
SAHG-SFDC
I have this class for which I need test class , what are the steps I should follow to get good coverage
Advance thanks
Test Class Assistance For Coverage
public with sharing class OptyProduct { Public List<OpportunityLineItem> ProdList{get;set;} public OptyProduct(ApexPages.StandardController controller) { ProdList = new List<OpportunityLineItem>(); ProdList =[SELECT Quantity,UnitPrice,TotalPrice,Sales_Price__c,Price_Type__c, Invoice_Frequency__c, Monthly_Minimum__c,product2.Name, ServiceDate FROM OpportunityLineItem where Opportunity.Id=:ApexPages.currentPage().getParameters().get('id')]; } }HI,
I have this class for which I need test class , what are the steps I should follow to get good coverage
Advance thanks
All Answers
I cannot be more thankful , Thank you so much! I got 100% coverage
How does this work though?
1. Class constructor parameter (controller instance) is not used anywhere in the class. So passing a null value do not have any negative impact. Ideally, if parameter is not used, then you should get rid of that unwanted parameter.
2. List of OpportunityLineItem is not used in the class (I suspect its used on vf page). As a result, if SOQL query returns 0 rows, still your class would not have failed because of the use of list variable (ProdList). Hence, all you had to do is to ensure current page has id parameter (value does not matter here as we are just testing for coverage. If you want your SOQL to return the list of line items then you will need to pass the valid opportunity value).
Line 9 is a simple assert to validate the size of list after initialization of controller. since we did not pass valid opportunity id with line items, product list size should be 0. Its as good as if(ProdList.size() > 0) then throw exception.