You need to sign in to do that
Don't have an account?
dandamudi
test class for trigger code coverage
got code coverage only 5% percentage how can i acheive this 75% more , please help me for 75% code coverage
trigger RepCompensation on Compensation__c(before insert, before update) {
for(Compensation__ccc: Trigger.New){
List<Compensation__c> cclist =[select id,Contract__c,Payment_Amount__c,Payment_Frequency1__c,Frequency_Months__c,Payment_Due_Date__c,Payment_Date_2__c,Payment_Date_3__c,Payment_Date_4__c,Payment_Amount1__c FROM Compensation__cWHERE id in : Trigger.New];
datetime cd = System.today();
if((cc.Payment_Frequency1__c == 'Annually' || cc.Payment_Frequency1__c == 'One Time') & cc.Payment_Frequency1__c <> Null){
If(cc.Frequency_Months__c <> Null && cc.Payment_Due_Date__c == Null){
if(cc.Frequency_Months__c == 'January'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),01,01);
}
if(cc.Frequency_Months__c == 'February'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),02,01);
}
if(cc.Frequency_Months__c == 'March'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),03,01);
}
if(cc.Frequency_Months__c == 'April'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),04,01);
}
if(cc.Frequency_Months__c == 'May'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),05,01);
}
if(cc.Frequency_Months__c == 'June'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),06,01);
}
if(cc.Frequency_Months__c == 'July'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),07,01);
}
if(cc.Frequency_Months__c == 'August'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),08,01);
}
if(cc.Frequency_Months__c == 'September'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),09,01);
}
if(cc.Frequency_Months__c == 'October'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),10,01);
}
if(cc.Frequency_Months__c == 'November'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),11,01);
}
if(cc.Frequency_Months__c == 'December'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),12,01);
}
}
}
test class
@isTest
public class TestRepCompensation{
public static testmethod void test1(){
datetime cd = System.today();
Account a = new Account(Name = 'Test Account', Account_Type__c = 'Agency', Hierarchy_1__c = 'Growth', Hierarchy_2__c = 'Growth Miscellaneous',
Hierarchy_3__c = 'Growth Miscellaneous', Picklist_Category__c = 'Medical');
insert a;
Contract c = new Contract(Status = 'Proposed/pending',Contract_Expiration_Date__c = date.newinstance(2017,03,01), AccountId = a.id,
StartDate = date.newinstance(2016,03,01));
insert c;
Compensation__c cc1 = new Compensation__c(Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'January',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),01,01));
insert cc1;
Compensation__c cc2 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'February',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),02,01));
insert cc2;
Compensation__c cc3 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'March',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),03,01));
insert cc3;
Compensation__c cc4 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'April',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),04,01));
insert cc4;
Compensation__c cc5 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'May',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),05,01));
insert cc5;
Compensation__c cc6 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'June',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),06,01));
insert cc6;
Compensation__c cc7 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'July',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),07,01));
insert cc7;
Compensation__c cc8 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'August',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),08,01));
insert cc8;
Compensation__c cc9 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'September',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),09,01));
insert cc9;
Compensation__c cc10 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'October',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),10,01));
insert cc10;
Compensation__c cc11 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'November',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),11,01));
insert cc11;
Compensation__c cc12 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'December',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),12,01));
insert cc12;
System.assert(cc12.Payment_Amount1__c==1000.00 );
trigger RepCompensation on Compensation__c(before insert, before update) {
for(Compensation__ccc: Trigger.New){
List<Compensation__c> cclist =[select id,Contract__c,Payment_Amount__c,Payment_Frequency1__c,Frequency_Months__c,Payment_Due_Date__c,Payment_Date_2__c,Payment_Date_3__c,Payment_Date_4__c,Payment_Amount1__c FROM Compensation__cWHERE id in : Trigger.New];
datetime cd = System.today();
if((cc.Payment_Frequency1__c == 'Annually' || cc.Payment_Frequency1__c == 'One Time') & cc.Payment_Frequency1__c <> Null){
If(cc.Frequency_Months__c <> Null && cc.Payment_Due_Date__c == Null){
if(cc.Frequency_Months__c == 'January'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),01,01);
}
if(cc.Frequency_Months__c == 'February'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),02,01);
}
if(cc.Frequency_Months__c == 'March'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),03,01);
}
if(cc.Frequency_Months__c == 'April'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),04,01);
}
if(cc.Frequency_Months__c == 'May'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),05,01);
}
if(cc.Frequency_Months__c == 'June'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),06,01);
}
if(cc.Frequency_Months__c == 'July'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),07,01);
}
if(cc.Frequency_Months__c == 'August'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),08,01);
}
if(cc.Frequency_Months__c == 'September'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),09,01);
}
if(cc.Frequency_Months__c == 'October'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),10,01);
}
if(cc.Frequency_Months__c == 'November'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),11,01);
}
if(cc.Frequency_Months__c == 'December'){
cc.Payment_Due_Date__c = date.newinstance(cd.year(),12,01);
}
}
}
test class
@isTest
public class TestRepCompensation{
public static testmethod void test1(){
datetime cd = System.today();
Account a = new Account(Name = 'Test Account', Account_Type__c = 'Agency', Hierarchy_1__c = 'Growth', Hierarchy_2__c = 'Growth Miscellaneous',
Hierarchy_3__c = 'Growth Miscellaneous', Picklist_Category__c = 'Medical');
insert a;
Contract c = new Contract(Status = 'Proposed/pending',Contract_Expiration_Date__c = date.newinstance(2017,03,01), AccountId = a.id,
StartDate = date.newinstance(2016,03,01));
insert c;
Compensation__c cc1 = new Compensation__c(Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'January',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),01,01));
insert cc1;
Compensation__c cc2 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'February',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),02,01));
insert cc2;
Compensation__c cc3 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'March',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),03,01));
insert cc3;
Compensation__c cc4 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'April',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),04,01));
insert cc4;
Compensation__c cc5 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'May',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),05,01));
insert cc5;
Compensation__c cc6 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'June',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),06,01));
insert cc6;
Compensation__c cc7 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'July',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),07,01));
insert cc7;
Compensation__c cc8 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'August',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),08,01));
insert cc8;
Compensation__c cc9 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'September',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),09,01));
insert cc9;
Compensation__c cc10 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'October',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),10,01));
insert cc10;
Compensation__c cc11 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'November',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),11,01));
insert cc11;
Compensation__c cc12 = new Compensation__c (Payment_Amount__c = 1000.00,Payment_Frequency1__c = 'Annually',
Frequency_Months__c = 'December',Contract__c = c.id, Payment_Amount1__c = 1000.00,Payment_Due_Date__c = date.newinstance(cd.year(),12,01));
insert cc12;
System.assert(cc12.Payment_Amount1__c==1000.00 );
All Answers