RunTest with Salesforce Tooling REST API (asynchronous and synchronous)
- Jun
- 03
- Posted by Lin
- Posted in Other, REST API, Salesforce, Tooling API
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.
2.apigee for Salesforce (https://apigee.com/console/salesforce)
3.A TestClass (Id=01p10000001Faws) such as:
(In fact,it is really slow, even will cost you more than 10 mins :()
First,we need to login apigee with Salesforce OAuth2.
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.
And we will find that a Test has been run at “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.
Set Request URL and Parameter like the following capture.
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 Account2.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.
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.
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”. 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.
1.ApexTestQueueItem [Document]
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.
Response
And test will not run at “Apex Test Execution” in this way. That is why running test with Sublime Text3 + MavensMate is always faster than running with Salesforce Developer Console,I suppose.Recent Posts
- Salesforce DevTools Release Notes (version 3.10.0) – mass edit custom fields on lightning
- Salesforce DevTools Release Notes (version 3.9.0) – Object Fields, SOQL Query Editor
- Salesforce DevTools Release Notes (version 3.8.0)
- Salesforce DevTools JUST HIT 10,000 USERS! THANK YOU!
- Using Promise for Apex Server-Side request in Lightning Component
Top Posts
- Salesforce DevTools – Powerful Salesforce developer tools, loved by over 50K developers - 222.8K views
- Date format and DateTime format - 206.9K views
- Salesforce Mass Editor (Chrome Extension) – Mass create, mass update, mass clone, mass delete on any list view. Support for both Classic and Lightning! - 159.6K views
- Setup an awesome Salesforce developer environment with Sublime Text 3 - 122.7K views
- Writing a Schedulable Batch Apex in Salesforce - 121.7K views
Categories
- APEX
- Apps
- Custom Label
- Custom Metadata
- Custom Setting
- Design & UI
- Event
- Heroku
- iOS & Object-c
- Lightnint Component
- Linux & Mac OS
- Metadata API
- Node.js
- Open Source
- Other
- PHP Framework
- Release Notes
- REST API
- Salesforce
- Salesforce DevTools
- Salesforce DX
- SOQL
- Tooling API
- Unit Tests
- Validation Rule
- Visualforce
- WordPress
You must be logged in to post a comment.