You need to sign in to do that
Don't have an account?
How can you exclude a block of code from some unit tests but not from others?
I know that it's possible to exclude a block of code from being executed with creative use of the following method:
Test.isRunningTest()However, I was hoping someone knew of a strategy for excluding a block of code from certain unit tests while allowing it to run in others. I have portions of a Trigger that I want to run for certain unit tests, but I'd prefer not to run the same portion of the trigger for other tests. Is there a common strategy for doing that? Any help would be greatly appreciated. Many thanks!
You have to created a TriggerHandler class and put a static varibale in it. When running the test class you can switch it on/off. Please find the code attached.
Triggger:-
Class:-
Test Class:- If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Regards,
Kapil
(forcecube@gmail.com)
All Answers
You have to created a TriggerHandler class and put a static varibale in it. When running the test class you can switch it on/off. Please find the code attached.
Triggger:-
Class:-
Test Class:- If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Regards,
Kapil
(forcecube@gmail.com)
Why on earth didn't I think of that? It seems so obvious to me now that I'm reading it! :) Excellent answer, Kapil. Thanks for sharing this!
Regards,
Mike