Seeing this error now if an object has an email alert on it during insert and using test.setMock
Disabling the workflow/process builder that contains the email alert and the test passes fine.
Test.setMock is inside or outside test.startTest() (does not matter). Test.starTest() and test.stopTest() enclose the code.
All triggered were disable and issue was narrowed down to the email alert workflows. At this point is seems to only be some email alerts and not all. I have not been able to narrow down what is different between the ones that cause the issue and the ones that do not.
Is this new or something that is known?
Code:
Account a = New Account();
test.startTest();
//Set Mock
//Make Callout
test.stopTest();
This causes the uncommitted work pending error.
Code above is about it. I added a field to the Account to check when creating records from test methods Account a = New Account(DoNotSendEmailWorkflow = true);
and set the workflow rule to evaluate that and if checked do not do workflow.
When I do this test works just fine.
So, a workflow rule that sends an email alert will cause test methods using mock implementations to fail due to uncommitted work pending.
Update 8-26-2016
This issue is still happening as I just ran into it again.
Update 10-25-2016
now scheduled to be resolved in Winter 17 patch 12
https://success.salesforce.com/issues_view?id=a1p300000008XHBAA2
UPDATE 11-04-2016
SF has resolved this issue. I have not tested it out yet but they now say it was fixed in Winter '17 Patch 12.0
https://success.salesforce.com/issues_view?id=a1p300000008XHBAA2
test.starttest - setMock() -testcode - test.stoptest()
? Might be clearer with a reduced set of your code – cropredy May 14 '15 at 2:10