In my Apex code, I already have an external HTTP callout.
Now, I aim to create a data mockup for testing purposes in sandboxes.
The mockup works as follows: instead of making a real callout, the Apex reads a static JSON value stored in a custom metadata type record. I toggle the mockup on/off with a boolean flag in a custom setting.
if (useMockup()) { // check the boolean flag in custom setting;
return getMockUpHttpResponse(); // the data is retrieved from custom metadata type record;
} else{
// do real http callout;
}
My challenge is how to unit test this logic. Custom metadata types are exposed to Apex code, and the record in the org determines whether the unit test succeeds or fails, which conflicts with the concept of unit testing.
Thanks for your help!