I have a trigger on a custom Student
object that is suppose to assign the lookup field Advisor
based off of another look up field Gender
. Basically my trigger goes:
...
if (newStudent.Gender__c == null) {
newStudent.addError('\'Gender\' missing');
return;
}
And my test goes:
Student__c newStudent = new Student__c();
// Skip assigning gender
insert newStudent;
I am able to get 100% code coverage for my trigger, but the test technically fails. If I assign the gender, I get a passed test but I don't get 100% code coverage.
How are you suppose to get 100% test coverage on a trigger that applies its own validation on a field?
Student__c
records, one with a gender specified and one without to cover these two data scenarios. Is there more complication to the test scenario here?insert
without a gender fails...