You need to sign in to do that
Don't have an account?

runOnce and test methods
Does anyone have a solution for the following situation:
The only way I can think of to get around this is to fudge the assert to match the test-only result, or use @SeeAllData=true and rely on preexisting data - neither very satisfactory.
- Trigger uses a static runOnce boolean class variable to prevent recursive firing
- Test method creates data that fires the trigger and runOnce is set
- Test method then performs a DML operation but the trigger doesn't fire because runOnce is already set
The only way I can think of to get around this is to fudge the assert to match the test-only result, or use @SeeAllData=true and rely on preexisting data - neither very satisfactory.
Or you could have a method on your runOnce class of 'resetAfterTestSetup()' if you don't want to expose the internal workings.
This seems like reasonable dependency injection for testing behaviour to me.
All Answers
Or you could have a method on your runOnce class of 'resetAfterTestSetup()' if you don't want to expose the internal workings.
This seems like reasonable dependency injection for testing behaviour to me.