You need to sign in to do that
Don't have an account?
Test Coverage on Validation trigger
Hi all,
can u help me develop a test coverage for a validation trigger. Heres my trigger and test coverage(which doesnt work well)
//trigger
trigger updateOthersJob on Job__c (before insert, before update) {
for (Job__c job : trigger.new) {
if((job.Not_Proceeding_Reason__c == 'Other') && (job.Please_specify_Other__c == null)) {
job.Not_Proceeding_Reason__c.addError('You are required to describe Other for Not Proceeding Reason.');
}
if((job.Not_Proceeding_Reason__c != 'Other') && (job.Please_specify_Other__c != null)) {
job.Please_specify_Other__c.addError('This is only required when the Reason for not proceeding is specified as "Other".');
}
}
}
//testclass
@isTest
private class Test_updateOthersJob {
static testMethod void myUnitTest() {
Job__c job = new Job__c();
job.Job_Status__c = '1. Unassigned';
job.Carpentry__c = true;
job.Not_Proceeding_Reason__c = 'Other';
insert job;
job.Not_Proceeding_Reason__c = '';
update job;
Job__c job1 = new Job__c();
job1.Job_Status__c = '1. Unassigned';
job1.Carpentry__c = true;
job1.Please_specify_Other__c = 'Other';
insert job1;
}
}
Thx
Hi,
How much coverage have you got? which portions of the code are not covered?
Hi prady
Thanks for the quick response.
When Ever I force the error i got 80% but there's an error. And I think I need to force that error in order to pass the validation
trigger. But when I dont force an error I only got 60% which doesn't pass
job.Not_Proceeding_Reason__c.addError('You are required to describe Other for Not Proceeding Reason.');
and
job.Please_specify_Other__c.addError('This is only required when the Reason for not proceeding is specified as "Other".');
Hi,
I am not sure if i understood you corectly...
With the test class you have written you are getting 80%?
I dont see a reason why you shouldnt be getting more coverage with the test class you have written.
I would add a couple of debug statements to see what the values of Not_Proceeding_Reason__c and Please_specify_Other__c in the trigger and if they are satisfying the conditions in the trigger
Hi,
There's nothing wrong with the coverage you have written except that you have missed out on giving proper values to your Please-specify_other__c field, because of which the trigger might be throwing a failure error.
This should be enough to give you a 100% coverage for the trigger :)
Hi Pardy,
I only got 60%..
it didn't pass the
line: job.Not_Proceeding_Reason__c.addError('You are required to describe Other for Not Proceeding Reason.');
and
line: job.Please_specify_Other__c.addError('This is only required when the Reason for not proceeding is specified as "Other".');
:(