You need to sign in to do that
Don't have an account?
your advice concerning test class on triggers
Hi there,
I just began to create test classes and I had a question about the good practices.
Assume we have a trigger that updates a "LastOrderDate__c" on Account, based on the field EffectiveDate in Order object.
We can have different cases :
Should I make only one test class including all the steps to cover all the cases ?
Should I then test with System.assertEquals the value of LastOrderDate after each action (create/delete) ?
Thanks for your help
I just began to create test classes and I had a question about the good practices.
Assume we have a trigger that updates a "LastOrderDate__c" on Account, based on the field EffectiveDate in Order object.
We can have different cases :
- We delete an order - Account had only this order => LastOrderDate__c becomes null
- We delete an order - Account had several orders => LastOrderDate__c becomes the max(EffectiveDate) of his other orders
- We create/update an order => LastOrderDate__c becomes the max(EffectiveDate) of all his orders
Should I make only one test class including all the steps to cover all the cases ?
- test class
- create order 1
- create order 2
- delete order 1
- delete order 2
- test class1
- create order
- test class2
- create order
- delete order
- test class3
- create order1
- create order2
- delete order1
- delete order2
Should I then test with System.assertEquals the value of LastOrderDate after each action (create/delete) ?
Thanks for your help
for this scenario you can create a single test class and yes you can use System.assertEquals ( you may decide to use this based on the controller/class logic).
Also if you have multiple classes which may need similar testing , you can create a utility class wherein you can create the common test data, may creation of the order.
Good luck !
All Answers
for this scenario you can create a single test class and yes you can use System.assertEquals ( you may decide to use this based on the controller/class logic).
Also if you have multiple classes which may need similar testing , you can create a utility class wherein you can create the common test data, may creation of the order.
Good luck !