We have a managed package that has executes a HTTP callout from a trigger that calls a future method on the insertion of new records on a particular object. We have a managed package extension that inserts records on the managed package object which invokes a callout through the managed package.
The problem is in test classes in the managed package extension. The test classes are failing because it is inserting these records which cause a callout through the managed package. Normally you would just implement Test.setMock(HttpCalloutMock.class,..) inside the Test.startTest() logic however it is not working.
From what I have read you must implement the Test.setMock method from within the managed package that is actually doing the callout. Has anyone dealt with this before?
Is the solution as simple as building in logic in the managed package trigger to recognize that it is being executed from a managed package extension and to then invoke Test.setMock from the trigger prior to the attempted callout?
- Managed Package Extension inserts new records
- Managed Package Extension sets a global variable value inside of the Managed Package
- Managed Package trigger fires and looks at the global variable and implements Test.setMock since it was invoked from the managed package extension.
Option 2: Add logic in the trigger to always invoke Test.setMock when it is running in a test context (Test.isRunningTest()).