You need to sign in to do that
Don't have an account?
How to increase test class coverage?
Hi All,
We want a new Pint is self-generated once checkbox Oct31 is checked (true), account and pint owner have to be the same, new pint's payroll date wil be 16 days more and new pint's schedule start date will be 9 days more of old pint's payroll date. I got this trigger and test class, the coverage is 70%, did not pass, please help me write the test class to increase coverage. Many thanks.
trigger Oct31Pint on Pint__c (after update) {
List<Pint__c> pints = new List<Pint__c>();
for (Pint__c p : Trigger.new) {
if (p.Oct31__c == true ) {
Pint__c newPint = new Pint__c();
newPint.Account__c = p.Account__c;
newPint.Pint_Owner__c = p.Pint_Owner__c;
newPint.Payroll_Date__c = p.Payroll_Date__c + 16;
newPint.Schedule_Start_Date_5_Biz_Days_Prior_PR__c = p.Payroll_Date__c + 9;
pints.add(newPint);
}
}
if(pints.size() > 0) insert pints;
}
TEST:
@isTest
public class TestOct31Pint
{
static testMethod void insertNewPint()
{
Account account = new Account();
account.Name = 'Test Account';
insert account;
Pint__c PintToCreate = new Pint__c();
PintToCreate.Account__c = account.Id;
insert PintToCreate;
Test.StartTest();
PintToCreate.Oct31__c = true;
update PintToCreate;
Test.StopTest();
}
}
We want a new Pint is self-generated once checkbox Oct31 is checked (true), account and pint owner have to be the same, new pint's payroll date wil be 16 days more and new pint's schedule start date will be 9 days more of old pint's payroll date. I got this trigger and test class, the coverage is 70%, did not pass, please help me write the test class to increase coverage. Many thanks.
trigger Oct31Pint on Pint__c (after update) {
List<Pint__c> pints = new List<Pint__c>();
for (Pint__c p : Trigger.new) {
if (p.Oct31__c == true ) {
Pint__c newPint = new Pint__c();
newPint.Account__c = p.Account__c;
newPint.Pint_Owner__c = p.Pint_Owner__c;
newPint.Payroll_Date__c = p.Payroll_Date__c + 16;
newPint.Schedule_Start_Date_5_Biz_Days_Prior_PR__c = p.Payroll_Date__c + 9;
pints.add(newPint);
}
}
if(pints.size() > 0) insert pints;
}
TEST:
@isTest
public class TestOct31Pint
{
static testMethod void insertNewPint()
{
Account account = new Account();
account.Name = 'Test Account';
insert account;
Pint__c PintToCreate = new Pint__c();
PintToCreate.Account__c = account.Id;
insert PintToCreate;
Test.StartTest();
PintToCreate.Oct31__c = true;
update PintToCreate;
Test.StopTest();
}
}
That's why the coverage is 70%.
All Answers
That's why the coverage is 70%.
But the reason is same.
@isTest
public class TestOct31Pint
{
static testMethod void insertNewPint()
{
Account account = new Account();
account.Name = 'Test Account';
insert account;
Pint__c.Payroll_Date__c = Today;
Pint__c PintToCreate = new Pint__c();
PintToCreate.Account__c = account.Id;
insert PintToCreate;
Test.StartTest();
PintToCreate.Oct31__c = true;
update PintToCreate;
Test.StopTest();
}
}
Pint__c PintToCreate = new Pint__c(Payroll_Date__c = Date.today());