You need to sign in to do that
Don't have an account?
sudhIr Narayan
Improve code coverage in my trigger
Hi,
Please suggest me am find challenge in improving performance in code coverage. Please advice me if this code is correct or not how to modify to get more code coverage.
Below code is working perfect only issue is with code coverage.
Please suggest me am find challenge in improving performance in code coverage. Please advice me if this code is correct or not how to modify to get more code coverage.
Below code is working perfect only issue is with code coverage.
trigger NewDiscountProgramUpdate on Opportunity (Before Update) { // ******** Trigger Created By Sudhir ************ // Loop through the incoming records list<opportunity> opp = new list<opportunity>(); for (Opportunity o : Trigger.new) { // Check for Deal Reg Not Null if ( o.FORCE_NSP__c == NULL && o.discount_program__c <> 'NSP' && o.Deal_Registration__c <> NULL ) { if ( o.Partner_Driven__c == 'Yes' && o.Partner_Led__c == 'No' && o.K_12__c == 'No' ) { o.discount_program__c = 'DEALREG/PI'; o.Abbv_Discount_Program__c = 'DR/PI'; } else if ( o.Partner_Driven__c == 'No' && o.Partner_Led__c == 'Yes' && o.K_12__c == 'No' ) { o.discount_program__c = 'DEALREG/PL'; o.Abbv_Discount_Program__c = 'DR/PL'; } else if ( o.Partner_Driven__c == 'Yes' && o.Partner_Led__c == 'Yes' && o.K_12__c == 'No' ) { o.discount_program__c = 'DEALREG/PI/PL'; o.Abbv_Discount_Program__c = 'DR/PI/PL'; } else if ( o.Partner_Driven__c == 'No' && o.Partner_Led__c == 'No' && o.K_12__c == 'Yes' ) { o.discount_program__c = 'DEALREG/K-12'; o.Abbv_Discount_Program__c = 'DR/K12'; } else if ( o.Partner_Driven__c == 'Yes' && o.Partner_Led__c == 'No' && o.K_12__c == 'Yes' ) { o.discount_program__c = 'DEALREG/PI/K-12'; o.Abbv_Discount_Program__c = 'DR/PI/K12'; } else if ( o.Partner_Driven__c == 'No' && o.Partner_Led__c == 'Yes' && o.K_12__c == 'Yes' ) { o.discount_program__c = 'DEALREG/PL/K-12'; o.Abbv_Discount_Program__c = 'DR/PL/K12'; } else if ( o.Partner_Driven__c == 'Yes' && o.Partner_Led__c == 'Yes' && o.K_12__c == 'Yes' ) { o.discount_program__c = 'DEALREG/PI/PL/K-12'; o.Abbv_Discount_Program__c = 'DR/PI/PL/K12'; } else { o.discount_program__c = 'DEALREG'; o.Abbv_Discount_Program__c = 'DR'; } } opp.add(o); } }
Please advice me also how to write test class for above trigger I wrote a test class which is giving only 14% code coverage.
Thanks
Sudhir
@isTest
public class TaskTest
{
public static testmethod void validating ()
{
// Add all the required field in the opportunity.
opportunity opp = new opportunity();
opp.Name = 'TestOppty';
opp.FORCE_NSP__c = 'No';
opp.Partner_Led__c = 'No';
opp.K_12__c ='No';
insert opp
opportunity oppty = new opportunity([select id, discount_program__c, Abbv_Discount_Program__c from Opportunity where id =: opp.id])
System.assertEquals(oppty.discount_program__c, ‘DEALREG’);
System.assertEquals(oppty.Abbv_Discount_Program__c, ‘DR’);
}
}
Since there is lot of if condition, Instead of satisfying all the if condition you insert a record which disobey all if conditions so your code may be covered.
Hope this helped!!
Can you share your test class?
You can refer below code: If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
Please find my complete trigger I tried above test class to create i get only 23% Please adivce me how to improve
After writing below test class i got 63% Please advice how to get 100%