Testing Queueable Apex
To test Queueable Apex, we follow the same pattern we have used for all our asynchronous code. We place the System.enqueueJob
call between a Test.startTest
method call and a Test.stopTest
method call to run the asynchronous process synchronously:
@isTest private class ExampleQueueable_Test { @isTest private static void testExecute() { Test.startTest(); System.enqueueJob(new ExampleQueueable()); Test.stopTest(); //Assert on expected changes } }
Note that if you were to run the following code:
@isTest private class ExampleQueueable_Test { @isTest private static void testExecute() { Test.startTest(); Id apexJobId = System.enqueueJob(new ExampleQueueable()); ...