Is there a way to wait for all @future method completes before starting the test?

I think Test.startTest() does not wait for future methods. I need the future method to be done in order to setup data for my test case. And this question causes unexpected results in my test class.

  • 1
    Can someone tell me that it is impossible for waiting future methods done before Test.startTest()?........
    – Oscar Tang
    Commented Jun 8, 2015 at 8:08

2 Answers 2


I don't think so. In testing, I believe that all of the async processes happen when you call Test.stopTest()

  • 1
    You might refer to the documentation: All asynchronous calls made after the startTest method are collected by the system. When stopTest is executed, all asynchronous processes are run synchronously.
    – sfdcfox
    Commented Jun 5, 2015 at 5:57
  • I am talking about Test.startTest(). I would like to call some future method to setup testing data. But I can't make them complete before starting the test.
    – Oscar Tang
    Commented Jun 5, 2015 at 6:10

Test.StartTest(); Test.StopTest();

1they reset your governor limits so you can test if your actual code is going to hit Limits. 2Test.StopTest(), actually forces your @future methods to run right now and return before progressing to the next step

@isTest private static void test_CalloutQueued() { // Setup my test data... FooController controller = new FooController(); Test.StartTest(); controller.save(); Test.StopTest(); // You can actually now assert that yes, it indeed was queued, // and has run, and has returned data. Since this is a callout?

  • I need to wait another future method between starttest and stoptest. That's why I need to wait for the future call finish before starttest...
    – Oscar Tang
    Commented Jun 5, 2015 at 11:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .