function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
dmchengdmcheng 

Winter 13 setMock callout fails for trigger / future method unit test

In case anyone is trying the new HttpCalloutMock to test a trigger ->  future method -> callout method combination:  i'm getting the same "uncommitted work pending" error as described in this thread:

 

http://boards.developerforce.com/t5/Apex-Code-Development/Testing-Webservice-Callouts-with-Winter-13-Test-setMock-fails/m-p/536485#M97364

 

This is occurring even when the only DML in my test code is the DML needed to fire the trigger.

 

The trigger and methods are working fine at the UI level, just not in unit tests.

BritishBoyinDCBritishBoyinDC

 

Take a look at the Salesforce Stack Exchange as well - lot's of posts about it, not many answers - seems to be a significant flaw in the design...

http://salesforce.stackexchange.com/search?q=mock

 

I also saw a post about deployment where support suggested moving all the callout classes to the top of the list (by changing the name no less) as it will fail if you try and make callouts after tests that invoke DML in the same deployment?  

Ron ReedRon Reed

Ran into the same problem and by prefixing the callout classes with AAA, causing them to be at the top of the list as suggested above, we are not seeing the error anymore.

dmchengdmcheng

So all you did was rename your callout classes by prefixing AAA, and it worked?  You didn't have to modify anything in the unit test code as far as re-ordering your data insert statements or callout statements, etc?

Ron ReedRon Reed

Yes, we prefixed the test class that was doing the mock callout, making that the first test that is run, and that caused the test to pass.

Duygu JohnstonDuygu Johnston
I had the same issue and prefixing the callout test class name with AAA fixed the problem