We have a custom Prescription object, associated to a Contact/Patient, which can be renewed (extended, essentially) or revised (some significant change) periodically. A renewal is straightforward; a revision requires review.
Prescriptions come in through our portal, and if they're really renewals, they automatically process. As they land in Salesforce, I look at each significant field to determine whether it's different from what we have on the Patient.
private Boolean Revision(Contact c, Prescription__c rx){}
evaluates each incoming Prescription and returns true if it's a Revised Prescription (if any significant fields has changed), or false if they haven't. Each field being evaluated goes through a section like this:
if(Prescription__c.field1__c <> Contact.field1__c){
result = true;
break;
}
If any one of these fields has changed, there's no reason to check any of the others - stop there, change the recordtype to 'Revision'.
I have unit tests for each of the fields being evaluated:
Prescription__c.field1__c = 'new value';
Contact.field1__c = 'old value';
System.assertEquals(true, RevisionRx(contact, prescription);
And the tests all pass. When I look at the test coverage, however, many of these fields' evaluations remain flagged red, and the test coverage is abysmal. If I run just the one field's test, then it goes blue. ~~~~~~
I thought about creating Utility methods to do the IsChanged() comparison, but it really wouldn't cut down on the code size because I still want to break; if any return true.
I really don't want to break this into individual, field-level methods which might test more easily, and I'd still need to group them all together in a big If/Else If to manage the breaks.
I can't slide by with 'Run All Tests', either -- I need coverage for each Change Set I deploy.
Thoughts?