Activity Forums Salesforce® Discussions When do we run the tests synchronously and when asynchronously in test classes ?

  • When do we run the tests synchronously and when asynchronously in test classes ?

    Posted by Anurag on September 5, 2018 at 3:14 pm

    When do we run the tests synchronously and when asynchronously in test classes ?

    shariq replied 5 years, 7 months ago 5 Members · 4 Replies
  • 4 Replies
  • Avnish Yadav

    Member
    September 5, 2018 at 5:52 pm

    Hello Anurag,

    If you select Disable Parallel Testing from Apex Test execution option then it will Always Run Synchronously.

    Disable Parallel Testing checkbox if checked, mandates the platform to run each test class one after the other. So, we can say that this setting is the test class specific. If the checkbox is unchecked, the platform will run the test classes in parallel.

    Always Run Asynchronously checkbox if checked, mandates the platform to run test methods in a single test class to run in parallel. If unchecked, the test methods will run one after the other.

    Hope this helps.

    Thanks!

  • madhulika shah

    Member
    September 6, 2018 at 6:10 am

    Hi Anurag,

    While making Run all test call, the job is queued for test run calculations, but for deployment to production, as its synchronous and "run all test" is always "true" in background, so, test classes must have to run to validate if components going in production are valid or not. This is one of the major the control check salesforce have imposed to make sure all the production instances have valid code on cloud.

    Hope this helps.

  • Parul

    Member
    September 21, 2018 at 12:57 pm

    hi

    ASYNCHRONOUS EXAMPLE. In solving many engineering problems, the software is designed to split up the overall problem into multiple individual tasks, and then execute them asynchronously. Inverting a matrix, or a finite element analysis problem, are good examples. In computing, sorting a list is an example. The quick sort routine, for example, splits the list into two lists, and sorts each of them by calling itself recursively. In both of the above examples, the two tasks can (and often were) executed asynchronously. They do not need to be on separate threads. Even a machine with one CPU, and only one thread of execution can be coded to initiate processing of a second task before a first one has completed. The only criterion is that the results of one task are not necessary as inputs to the other task. As long as the start and end times of the tasks overlap, (possible only if the output of neither is needed as inputs to the other), they are being executed asynchronously, no matter how many threads are in use.

    SYNCHRONOUS EXAMPLE. Any process consisting of multiple tasks where the tasks must be executed in sequence, but one must be executed on another machine (Fetch and/or update data, get a stock quote from a financial service, etc.). If it's on a separate machine it is on a separate thread, whether synchronous or asynchronous.

     

    THanks

  • shariq

    Member
    September 21, 2018 at 1:08 pm

    Hi,

    All tests started through the Salesforce user interface now run asynchronously. Tests that are run as part of a deployment, a package install, or a package upload still run synchronously.

    Thanks

Log In to reply.

Popular Salesforce Blogs