+ Start a Discussion
Zach AckermanZach Ackerman 

Test Class Coverage not at 100%

I am having trouble getting my test class to 100% currently it is at 24%.

@isTest
public class PlanPackageNamesTest
{
      static testMethod void myUnitTest()
    {
        Plan__c plan = new Plan__c();
       
        plan.Name='Ultimate Health Diamond';
        plan.Product_Name__c='UH';
        plan.Carrier_Vendor__c='Transamerica';
        Plan.Annual_Family_Maximum__c=100000;
        Plan.Annual_Single_Maximum__c=100000;
        Plan.Vision__c=1500;
        Plan.Dental__c=5000;
        Plan.RX__c=4000;
        Plan.Counseling__c=3000;
        Plan.Wellness__c=1500;
        Plan.Medical_Equipment__c=10000;
        Plan.Executive_Physical__c=2500;
        Plan.Medical_Expense_Coverage__c='All 213 Eligible';
        Plan.Deductible__c=0;
        Plan.Co_insurance__c=0;
        plan.armada_plan_package_name__c='Diamond';
        plan.Policy_Group_Number__c='111';
        plan.Plan_Division__c='000A';
        plan.services_phone_number__c='1-888-8888'
       insert plan;
        plan.annual_single_maximum__c=110000;
        plan.annual_family_maximum__c=110000;
       plan.vision__c=11000;
        plan.dental__c=11000;
        plan.RX__c=11000;
        plan.Counseling__c=11000;
        plan.wellness__c=11000;
        plan.medical_equipment__c=11000;
        plan.executive_physical__c=11000;
        update plan;
        }
}






Below is my Trigger 



Trigger PlanPackageNames on Plan__c (Before Insert,Before Update){

    for (Plan__c Plan : Trigger.new){
 
        IF(Plan.Armada_Plan_Package_Name__c == 'Diamond' &&
        Plan.Sum_of_Benefits__c ==227500){
        Plan.Name= 'Ultimate Health'+' '+'Diamond';
        }
        IF(Plan.Armada_Plan_Package_Name__c == 'Diamond' &&
        Plan.Sum_of_Benefits__c ==0){
        Plan.Name= 'Ultimate Health'+' '+'Diamond';
        }
        IF(Plan.Armada_Plan_Package_Name__c=='Diamond'&&
        Plan.Sum_of_Benefits__c!=227500){
        Plan.Name= 'Ultimate Health'+' '+'Modified'+' '+'Diamond';
        }
        IF(Plan.Armada_Plan_Package_Name__c=='Platinum'&&
        Plan.Sum_of_Benefits__c!=115000){
        Plan.Name= 'Ultimate Health'+' '+'Modified'+' '+'Platinum';
        }
        IF(Plan.Armada_Plan_Package_Name__c=='Platinum'&&
        Plan.Sum_of_Benefits__c==0){
        Plan.Name= 'Ultimate Health'+' '+'Platinum';
        }
        IF(Plan.Armada_Plan_Package_Name__c=='Platinum'&&
        Plan.Sum_of_Benefits__c==115000){
        Plan.Name= 'Ultimate Health'+' '+'Platinum';
        }
        IF(Plan.Armada_Plan_Package_Name__c=='Gold'&&
        Plan.Sum_of_Benefits__c!=57500){
        Plan.Name= 'Ultimate Health'+' '+'Modified'+' '+'Gold';
        }
        IF(Plan.Armada_Plan_Package_Name__c=='Gold'&&
        Plan.Sum_of_Benefits__c==0){
        Plan.Name= 'Ultimate Health'+' '+'Gold';
        }
        IF(Plan.Armada_Plan_Package_Name__c=='Gold'&&
        Plan.Sum_of_Benefits__c==57500){
        Plan.Name= 'Ultimate Health'+' '+'Gold';
        }
        IF(Plan.Armada_Plan_Package_Name__c=='Diamond Plus'&&
        Plan.Sum_of_Benefits__c!=270000){
        Plan.Name= 'Ultimate Health'+' '+'Modified'+' '+'Diamond Plus';
        }
        IF(Plan.Armada_Plan_Package_Name__c=='Diamond Plus'&&
        Plan.Sum_of_Benefits__c==0){
        Plan.Name= 'Ultimate Health'+' '+'Diamond Plus';
        }
        IF(Plan.Armada_Plan_Package_Name__c=='Diamond Plus'&&
        Plan.Sum_of_Benefits__c==270000){
        Plan.Name= 'Ultimate Health'+' '+'Diamond Plus';
        }
        

         IF(Plan.Armada_Plan_Package_Name__c == 'Diamond' &&
        Plan.Sum_of_Benefits__c ==0)
        {
        Plan.Annual_Family_Maximum__c=100000;
        Plan.Annual_Single_Maximum__c=100000;
        Plan.Vision__c=1500;
        Plan.Dental__c=5000;
        Plan.RX__c=4000;
        Plan.Counseling__c=3000;
        Plan.Wellness__c=1500;
        Plan.Medical_Equipment__c=10000;
        Plan.Executive_Physical__c=2500;
        Plan.Medical_Expense_Coverage__c='All 213 Eligible';
        Plan.Deductible__c=0;
        Plan.Co_insurance__c=0;
        }
        IF(Plan.Armada_Plan_Package_Name__c == 'Gold' &&
        Plan.Sum_of_Benefits__c ==0)
        {
        Plan.Annual_Family_Maximum__c=25000;
        Plan.Annual_Single_Maximum__c=25000;
        Plan.Vision__c=500;
        Plan.Dental__c=2000;
        Plan.RX__c=1500;
        Plan.Counseling__c=1000;
        Plan.Wellness__c=500;
        Plan.Medical_Equipment__c=1000;
        Plan.Executive_Physical__c=1000;
        Plan.Medical_Expense_Coverage__c='All 213 Eligible';
        Plan.Deductible__c=0;
        Plan.Co_insurance__c=0;
        }
        IF(Plan.Armada_Plan_Package_Name__c == 'Platinum' &&
        Plan.Sum_of_Benefits__c ==0)
        {
        Plan.Annual_Family_Maximum__c=50000;
        Plan.Annual_Single_Maximum__c=50000;
        Plan.Vision__c=1000;
        Plan.Dental__c=4000;
        Plan.RX__c=2500;
        Plan.Counseling__c=2000;
        Plan.Wellness__c=1000;
        Plan.Medical_Equipment__c=2500;
        Plan.Executive_Physical__c=2000;
        Plan.Medical_Expense_Coverage__c='All 213 Eligible';
        Plan.Deductible__c=0;
        Plan.Co_insurance__c=0;
        }
        IF(Plan.Armada_Plan_Package_Name__c == 'Diamond Plus' &&
        Plan.Sum_of_Benefits__c ==0)
        {
        Plan.Annual_Family_Maximum__c=100000;
        Plan.Annual_Single_Maximum__c=100000;
        Plan.Vision__c=10000;
        Plan.Dental__c=10000;
        Plan.RX__c=10000;
        Plan.Counseling__c=10000;
        Plan.Wellness__c=10000;
        Plan.Medical_Equipment__c=10000;
        Plan.Executive_Physical__c=10000;
        Plan.Medical_Expense_Coverage__c='All 213 Eligible';
        Plan.Deductible__c=0;
        Plan.Co_insurance__c=0;
       
        }
        
                                                }
                                
                                        }
sridharbsridharb
Hi Zach,

From a quick glance at your code through I understand all the IF condition based on mostly 2 fileds but the condistion parameters are different.

Firstly I  Recommand you too use workflow as if you are able to acheive all your requirements of the Trigger. I think so you, then you doesnt need to worry about Trigger and Code coverage.

If you Trigger writting is definitive for your case, no problem just keep going. 

The reason for not enough coverage is you have only 1 insert and 1 update statement which doesnt enough to satisfy all the IF conditions.
you have to insert or update Plan records  with the different values to satisfy every individual IF conditions there in your trigger.

For suppose take first 2 IF conditions, To get coverage for all these lines you have to 

create Plan object as
​ Plan__C p = new Plan__c(Armada_Plan_Package_Name__c == 'Diamond',Sum_of_Benefits__c ==227500 );
insert p;

either change and update or create one more as follwoing
p = new Plan__c(Armada_Plan_Package_Name__c == 'Diamond',Sum_of_Benefits__c ==0);



 
IF(Plan.Armada_Plan_Package_Name__c == 'Diamond' &&
        Plan.Sum_of_Benefits__c ==227500){
        Plan.Name= 'Ultimate Health'+' '+'Diamond';
        }
        IF(Plan.Armada_Plan_Package_Name__c == 'Diamond' &&
        Plan.Sum_of_Benefits__c ==0){
        Plan.Name= 'Ultimate Health'+' '+'Diamond';
        }



Regards
Sri
I appreciate your acknowledgment as best answer if this helps you.
Zach AckermanZach Ackerman
I made two inserts and got to 38%. I figured I needed to do an update as well, but my select is not returning any rows. 


@isTest

 

public class PlanPackageNamesTest

{

 

      static testMethod void myUnitTest()

      

    {

        Plan__c plan = new Plan__c();
        
        plan.Name='Ultimate Health Diamond';
        plan.Product_Name__c='UH';
        plan.Carrier_Vendor__c='Transamerica';
        Plan.Annual_Family_Maximum__c=0;
        Plan.Annual_Single_Maximum__c=0;
        Plan.Vision__c=0;
        Plan.Dental__c=0;
        Plan.RX__c=0;
        Plan.Counseling__c=0;
        Plan.Wellness__c=0;
        Plan.Medical_Equipment__c=0;
        Plan.Executive_Physical__c=0;
        Plan.Medical_Expense_Coverage__c='All 213 Eligible';
        Plan.Deductible__c=0;
        Plan.Co_insurance__c=0;
        plan.armada_plan_package_name__c='Diamond';
        plan.Policy_Group_Number__c='111';
        plan.Plan_Division__c='000A';
        plan.services_phone_number__c='1-888-8888';
insert plan;
       plan= new Plan__c();
        plan.Name='Ultimate Health Diamond';
        plan.Product_Name__c='UH';
        plan.Carrier_Vendor__c='Transamerica';
        Plan.Annual_Family_Maximum__c=100000;
        Plan.Annual_Single_Maximum__c=100000;
        Plan.Vision__c=1500;
        Plan.Dental__c=5000;
        Plan.RX__c=4000;
        Plan.Counseling__c=3000;
        Plan.Wellness__c=1500;
        Plan.Medical_Equipment__c=10000;
        Plan.Executive_Physical__c=2500;
        Plan.Medical_Expense_Coverage__c='All 213 Eligible';
        Plan.Deductible__c=0;
        Plan.Co_insurance__c=0;
        plan.armada_plan_package_name__c='Diamond';
        plan.Policy_Group_Number__c='111';
        plan.Plan_Division__c='001A';
        plan.services_phone_number__c='1-888-8888';
        plan.external_id__c='111001ATransamericaDiamond';   
 insert plan;
 plan= [SELECT external_id__c,Annual_family_maximum__c,Annual_single_maximum__c,vision__c,dental__c,RX__c,Counseling__c,Wellness__c,Medical_Equipment__c,executive_physical__c,Medical_Expense_Coverage__c,Deductible__c,Co_insurance__c FROM plan__c WHERE external_id__c =:plan.external_id__c];
        plan.external_id__c='111001ATransamericaDiamond';
        Plan.Annual_Family_Maximum__c=110000;
        Plan.Annual_Single_Maximum__c=110000;
        Plan.Vision__c=2500;
        Plan.Dental__c=6000;
        Plan.RX__c=7000;
        Plan.Counseling__c=8000;
        Plan.Wellness__c=2500;
        Plan.Medical_Equipment__c=1000;
        Plan.Executive_Physical__c=500;
        Plan.Medical_Expense_Coverage__c='All 213 Eligible';
        Plan.Deductible__c=0;
        Plan.Co_insurance__c=0;


 update plan;  



              

    
}

}