You need to sign in to do that
Don't have an account?
Money Care 7
Test class code coverage increase
Hi All
I have created a vf page and class for display record based on piclist value.i have written test class for this but its code covrage is 23%.how to improve this code coverage
I have created a vf page and class for display record based on piclist value.i have written test class for this but its code covrage is 23%.how to improve this code coverage
<apex:page controller="displaylead" sidebar="false" showHeader="false"> <apex:form id="frm"> <apex:selectList size="1" value="{!getcasetype}" > <apex:selectOptions value="{!casestatus}"> </apex:selectOptions> <apex:actionSupport event="onchange" action="{!displaycaselist}"/> </apex:selectList> <apex:outputLabel id="pnl1" > <apex:pageBlock > <apex:pageBlockTable value="{!caselst}" var="cse"> <apex:column value="{!cse.Name}"/> <apex:column value="{!cse.Company}"/> <apex:column value="{!cse.Phone}"/> <apex:column value="{!cse.Title}"/> <apex:column value="{!cse.Email}"/> <apex:column value="{!cse.LeadSource}"/> <apex:column value="{!cse.Status}"/> <apex:column value="{!cse.Catagory__c }"/> </apex:pageBlockTable> </apex:pageBlock> </apex:outputLabel> </apex:form> </apex:page>
public class displaylead { public string getcasetype{get;set;} public void displaylead (){ } public list<Lead> caselst{get;set;} public list<selectoption>getcasestatus(){ list<selectoption>selectopt=new list<selectoption>(); selectopt.add(new selectoption('Corporate','Corporate')); selectopt.add(new selectoption('Government','Government')); selectopt.add(new selectoption('Nonprofit','Nonprofit')); selectopt.add(new selectoption('Foundation','Foundation')); selectopt.add(new selectoption('Nonprofit','Nonprofit')); selectopt.add(new selectoption('NKC Member','NKC Member')); selectopt.add(new selectoption('WildTeam Staff','WildTeam Staff')); selectopt.add(new selectoption('Individual','Individual')); selectopt.add(new selectoption('Media','Media')); selectopt.add(new selectoption('Donor','Donor')); selectopt.add(new selectoption('FMCG','FMCG')); selectopt.add(new selectoption('Others','Others')); return selectopt; } public void displaycaselist(){ caselst=new list<Lead>(); caselst=[SELECT Name,Company,Phone, Title,Email,LeadSource,Status,Catagory__c from Lead where Catagory__c=:getcasetype]; } }
@isTest public class displayleadTest { static testMethod void displayleadT() { List<Lead> lstPattern = new List<Lead>(); Lead p1 = new Lead(); p1.Company='Test Patttern'; p1.Catagory__c = 'xxxx'; p1.Title='sfdc'; p1.Email='sfdc@abc.com'; p1.LeadSource='sfdc'; p1.Status='sfdc'; insert lstPattern; displaylead gp = new displaylead(); gp.displaycaselist(); PageReference pageref = Page.displaylead; Test.setCurrentPageReference(pageref); } }
Try this out:
Please mark this question as solved if this helps you so that others can view it as aproper solution.
Thanks,
Apoorv