You need to sign in to do that
Don't have an account?
KatherineC
How to write test class for this trigger
I got this trigger with some help, now I tried to run a test got 0 coverage, please help. When a Pint's field Semi-monthly check box is checked, a new pint is generated.
TRIGGER:
trigger SemiMonthly on Pint__c (after update) {
List<Pint__c> pints = new List<Pint__c>();
for (Pint__c p : Trigger.new) {
if (p.Semi_Monthly__c == true ) {
Pint__c newPint = new Pint__c();
newPint.Account__c = p.Account__c;
pints.add(newPint);
}
}
if(pints.size() > 0) insert pints;
}
TEST
@isTest
public class TestSemiMonthly {
static testMethod void insertNewPint() {
Pint__c PintToCreate = new Pint__c();
PintToCreate.Account__c = 'ABC';
insert PintToCreate;
}
}
TRIGGER:
trigger SemiMonthly on Pint__c (after update) {
List<Pint__c> pints = new List<Pint__c>();
for (Pint__c p : Trigger.new) {
if (p.Semi_Monthly__c == true ) {
Pint__c newPint = new Pint__c();
newPint.Account__c = p.Account__c;
pints.add(newPint);
}
}
if(pints.size() > 0) insert pints;
}
TEST
@isTest
public class TestSemiMonthly {
static testMethod void insertNewPint() {
Pint__c PintToCreate = new Pint__c();
PintToCreate.Account__c = 'ABC';
insert PintToCreate;
}
}
Better approach is to create a test account record inside your test method and use that as a parent:
All Answers
Stack Trace: Class.TestSemiMonthly.insertNewPint: line7, column 1
But I did have an account named ABC
Better approach is to create a test account record inside your test method and use that as a parent: