You need to sign in to do that
Don't have an account?
Nagendra Singh 42
Apex unit test for handler methods?
For writing unit test for trigger handler, is it necessay to call the methods in trigger handler by giving an insert, update or delete statement?
Or Can I call the trigger handler methods directly and pass the required argument through the method parameters.
The second approach seems to be the correct way of unit testing the handlers and other classes except the trigger. This will ensure that you have a set of data before passing it to the method, rather than depending upon the trigger to execute the handler methods.
Please suggest which one is better?
Or Can I call the trigger handler methods directly and pass the required argument through the method parameters.
The second approach seems to be the correct way of unit testing the handlers and other classes except the trigger. This will ensure that you have a set of data before passing it to the method, rather than depending upon the trigger to execute the handler methods.
Please suggest which one is better?
- Simulating CRUD within testing scope Test.startTest() with asserting the result.
- This will help to simulate other related trigger,validation rule,workflow, etc in the System.
- It will also tell you if you hit any governance limit.
- Unit test individual public method in the trigger handler.
In otherwords, I cover more by testing both and that is the purpose of testing :)