I'm trying test a critical part of an application that is in a batch process and makes callouts to a server.
MyObject__c obj = new MyObject__c(name='test');
insert obj;
Test.startTest();
Test.setMock(WebServiceMock.class, new MyWebServiceMock());
//run the batch process
MyBatchProcess.createBatch(obj);
Test.stopTest();
When I attempt to "mock" the callout, I get hit with this bug:
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
According to the docs on testing callouts, this shouldn't happen.
Dug into it a bit more and found this article where someone opened a case. Salesforce apperently responded by saying to "use the isTestRunning() method to avoid the callout".
This is obviously not ideal, as It makes it very hard to do any useful assertions. The only work around I can think of is to overload the batch constructor and pass my test inputs in. I would really like to avoid this if possible.
Anyone got a solution?