RunTest with Salesforce Tooling REST API (asynchronous and synchronous)

Salesforce supports running test with Tooling REST API ,which are runTestsAsynchronous and runTestsSynchronous.
Reference: https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/intro_rest_overview.htm

In this post I’ll show you what is the difference between runTestsAsynchronous and runTestsSynchronous.

Prepare

1.Salesforce Account
2.apigee for Salesforce (https://apigee.com/console/salesforce)
3.A TestClass (Id=01p10000001Faws) such as:

1.runTestsAsynchronous

Running tests asynchronously allows methods to process in parallel, cutting down your test run times.
(In fact,it is really slow, even will cost you more than 10 mins :()

First,we need to login apigee with Salesforce OAuth2.
apigee apigee-auth2 REST API Version after V28.0 supports Tooling API,so change the endpoint from [https://na14.salesforce.com/services/data/v24.0/] to [https://na14.salesforce.com/services/data/v33.0//tooling/].
Set Request URL and Parameter like the following capture then send request. apigee-runTestsAsynchronous

Response

As we see,the request will return an object Id,actually,it is an AsyncApexJob Id.
And we will find that a Test has been run at “Apex Test Execution”. Apex Test Execution Then how do we get the details of this Test Result?
Use Tooling API we can also Query the details from related sObjects. Here is the sObjects ER. ER

1.ApexTestQueueItem [Document]

apigee-ApexTestQueueItem

Response

2.ApexTestResult [Document]

Response

3.ApexCodeCoverage [Document]

Response

2.runTestsSynchronous

As the word, runTestsSynchronous will execute Apex tests synchronously so we can get the Test Result directly.
Set Request URL and Parameter like the following capture. apigee-runTestsSynchronous

Response

And test will not run at “Apex Test Execution” in this way. Apex Test Execution-runTestsSynchronous That is why running test with Sublime Text3 + MavensMate is always faster than running with Salesforce Developer Console,I suppose.

Related Post

Setup an awesome Salesforce developer environment ... Why Sublime Text 3 ? I've been working with Force.com for about 2 years, and always using Eclipse+Force.com IDE(See here, Eclipse Force.com IDE Installation)as my development environment. I don't think it is really difficult to use, but it could be more friendly. For example: 1. It doesn't suppo...
Using URL parameters on Salesforce standard pages Salesforce has many URL parameters can be used on its standard page, with this kind of parameters, you can do some URL hacking on it, as below: Note: All of parameters must be encoded with UTF-8. Login page There are two ways to login and access into Salesforce from url. 1. https://
Write Apex Test Classes efficiently with Tesforce 1.Why Tesforce The Test Classes are required to deploy Apex to a production environment or to be packaged and placed on Force.com AppExchange, it must provide at least 75% code coverage. That will be a huge workload to SFDC Developers if the project(application) include a lot of Apex Classes,the...
Salesforce Mass Editor (Chrome Extension) – ... This's my second Chrome Extension (First one is HERE) this year, named "Salesforce Mass Editor" and it supports for doing the below things : ・Makes any Salesforce list view to be a powerful mass editor. ・Mass insert, mass clone, mass update, mass delete, ALL-IN-ONE. ・Export record data to CSV fi...