0

I want to invoke a Process from the record base Process using invocable apex which invokes Process by making an HTTP request to the Rest API. But when I try that it's causing many of our existing tests to fail because of Mock issue.

For example, Lead Object Process invokes Apex class which makes an HTTP request to the Rest API to call other Process. So in any test class where DML is performed on Lead object between Test.startTest() and Test.stopTest() gives the mock error.

Can anyone suggest what could be the best way to handle this error?

Either should I update all of the test classes to set the Mock or in the Invocable class to check if Test is running?

2 Answers 2

2

Either should I update all of the test classes to set the Mock or in the Invocable class to check if Test is running?

This is a broader issue and will depend on multiple factors and how you want to approach it. You can choose one or the other approach.

But, if you really want to make sure that you want to Test the code you have written, then you should refactor your Test classes instead to include testing callouts. This will not only provide code coverage but also ensure that your functionality works as expected.

Few good places to get started on testing callouts are:

0

Test is running allows the production code dynamically detects and run code in conditions. Mocks extracts the logic out of the production code and puts into unit tests.

For simple scenario, both fulfil the requirement.

However, in order to unit-test handling various callout result scenarios, such as "timed out", "different status codes", "different payload content", mocking is much more flexible.

For instance, I might create unit tests as below using different Mocking inside.

WhenCalloutReturn400ThenThrowErrorA()
WhenCalloutReturn404ThenThrowErrorB()
WhenCalloutReturn200ThenReturnData()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .