You need to sign in to do that
Don't have an account?

How do I cover apex class variables in Apex Test class?
I want to cover atleast 75% of class. Now am on 74% just need only one percent but i found it hard. One part of my method is not covering that contains variables and its assignments.
above apex class code is one part of condition checking. This part is not covering in my Test class. Help me to cover this.
variables are Discount, MDiscount and UnitRate
if( Discount != 0 && MDiscount != 0) { Discount = ((UnitRate )*Discount)/100; MDiscount = ((UnitRate - Discount)*MDiscount)/100; objvar.Discount__c = Discount; objvar.MDiscount__c = MDiscount; } else if(Discount != 0 && MDiscount == 0) { Discount = ((UnitRate )*Discount)/100; objvar.Discount__c = Discount; } else if(Discount == 0 && MDiscount != 0) { MDiscount = ((UnitRate )*MDiscount)/100; objvar.MDiscount__c= MDiscount; } else { objvar.Discount__c = 0; objvar.MDiscount__c = 0; }
above apex class code is one part of condition checking. This part is not covering in my Test class. Help me to cover this.
variables are Discount, MDiscount and UnitRate
Basically if it class level variable ,then you need to use in test class with instance of the class and dot notation.
Like Class_Name clsnm=new Class_Name ();
clsnm.Discount=10;
If it is provate then add @TestVisible before the varibale .
To know more detail ablout the annotation you can check below link .
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_testvisible.htm
Thanks
Mnaoj
This should cover all of your code and will always fire.