I've moved a lot of my trigger code over into class methods so I can control what order the logic happens in. Each object has one Trigger like this, and each Trigger may might call up to a dozen different classes, and might call the same class method at different points depending on the context.
Below is a demonstration of how I've structured it :
Trigger ContactTrigger(...)
if(Trigger.isInsert){
ContactController.notifyUser(Trigger.new);
ContactController.assignPhoneNumber(Trigger.new);
AccountController.AssignToOrg(Trigger.new); }
if(Trigger.isDelete){
ContactController.notifyUser(Trigger.old);
ContactController.notifyContact(Trigger.old);
The ContactController would be just a heap of different methods relevant to the Contact object.
Anyway, I've written plenty of Test Methods which focus on one particular class function, or one particular context (i.e. one test for inserting, one for updating, one for deleting). COLLECTIVELY, they cover the class entirely, but the coverage amount displayed only reflects the test method that offers the least coverage. For example, the system focuses on a Unit test that covers 12% of the code (one method) rather than one that covers 90%.
I'm not really sure what to do here. I need to get adequate coverage on classes, but I also need to keep my unit tests specialised to avoid hitting governor limits. Perhaps I need to rethink my code structure?
Thanks in advance for any guidance,
Lachlan.