Basically, I'm getting the dreaded "System.CalloutException: You have uncommitted work pending." exception even though I'm 99.999% sure I'm not making any DML statements after running Test.startTest()
.
I've reduced my test to the simplest form and am still getting the error.
@isTest static void test_WTFSALESFORCE() {
abc__c abc = new abc__c(
Name = 'test');
insert abc;
//set mock
MockHttpResponseGenerator mock =
new MockHttpResponseGenerator('http://google.com','Hello World');
Test.startTest();
Test.setMock(HttpCalloutMock.class, mock);
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('http://google.com');
req.setMethod('GET');
// Send the request, and return a response
HttpResponse res = h.send(req);
String resp = res.getBody();
Test.stopTest();
}
It is embarrassing how long I've spent trying to debug this with no progress...
The object in question is a dummy object and not part of any workflows or triggers.
Am I missing something?
Also the test passes fine in a Full Copy Sandbox that was refreshed less than a month ago.