I have implemented an API to communicate with the external system. After 18th of August test that i have on production have started failing showing the infamous:
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
The weird thing is that those same tests are passing without any issues on the Sandbox, and as a matter of fact have been passing on Production until about two weeks ago. This is happening for all tests that have some sort of callouts happening after INSERT/UPDATE operations required to create the proper dataset for the test(s).
I have read the Performing DML Operations and Mock Callouts before and now so i can say i'm aware how these tests should be done (as said those tests are passing on the sandbox).
Pseudo code for tests:
DoTestDataSetup();//generate all records, insert them and do some updates if necessary Test.setMock(HttpCalloutMock.class,new myMockImplementation()); Test.startTest(); DoMyFutureMethodWithCallout(); Test.stopTest();
I know that the link I pasted says setMock() should be called inside the startTest() and I have tried it and got the same result.
Have there been some recent updates that could have affected this behavior?
IMPORTANT: code in production and in sandbox is completely the same i've done diff on them so the issue is not caused by code being invalid