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?
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.
This issue is still happening as I just ran into it again.
now scheduled to be resolved in Winter 17 patch 12
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