Back to Collection Items
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loHttp = createobject("CkHttp")
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "classNames": "comma-separated list of class names",
// "classids": "comma-separated list of class IDs",
// "suiteNames": "comma-separated list of test suite names",
// "suiteids": "comma-separated list of test suite IDs",
// "maxFailedTests": "integer value",
// "testLevel": "TestLevel enum value",
// "skipCodeCoverage": "boolean value"
// }
loJson = createobject("CkJsonObject")
loJson.UpdateString("classNames","comma-separated list of class names")
loJson.UpdateString("classids","comma-separated list of class IDs")
loJson.UpdateString("suiteNames","comma-separated list of test suite names")
loJson.UpdateString("suiteids","comma-separated list of test suite IDs")
loJson.UpdateString("maxFailedTests","integer value")
loJson.UpdateString("testLevel","TestLevel enum value")
loJson.UpdateString("skipCodeCoverage","boolean value")
// Adds the "Authorization: Bearer <access_token>" header.
loHttp.AuthToken = "<access_token>"
loHttp.SetRequestHeader("Content-Type","application/json")
loResp = loHttp.PostJson3("https://domain.com/services/data/v{{version}}/tooling/runTestsAsynchronous","application/json",loJson)
if (loHttp.LastMethodSuccess = .F.) then
? loHttp.LastErrorText
release loHttp
release loJson
return
endif
loSbResponseBody = createobject("CkStringBuilder")
loResp.GetBodySb(loSbResponseBody)
loJResp = createobject("CkJsonObject")
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = .F.
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + str(lnRespStatusCode)
if (lnRespStatusCode >= 400) then
? "Response Header:"
? loResp.Header
? "Failed."
release loResp
release loHttp
release loJson
release loSbResponseBody
release loJResp
return
endif
release loResp
release loHttp
release loJson
release loSbResponseBody
release loJResp
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
-d '{
"classNames": "comma-separated list of class names",
"classids": "comma-separated list of class IDs",
"suiteNames": "comma-separated list of test suite names",
"suiteids": "comma-separated list of test suite IDs",
"maxFailedTests": "integer value",
"testLevel": "TestLevel enum value",
"skipCodeCoverage": "boolean value"
}
or
{
"tests": [
{
"className": "YourClassName",
"testMethods": [
"testMethod1",
"testMethod2",
"testMethod3"
]
}
],
"maxFailedTests": "integer value",
"testLevel": "TestLevel enum value",
"skipCodeCoverage": "boolean value"
}'
https://domain.com/services/data/v{{version}}/tooling/runTestsAsynchronous
Postman Collection Item JSON
{
"name": "Tooling Run Tests Async",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"classNames\": \"comma-separated list of class names\",\n \"classids\": \"comma-separated list of class IDs\",\n \"suiteNames\": \"comma-separated list of test suite names\",\n \"suiteids\": \"comma-separated list of test suite IDs\",\n \"maxFailedTests\": \"integer value\",\n \"testLevel\": \"TestLevel enum value\",\n \"skipCodeCoverage\": \"boolean value\"\n}\n\nor \n\n{\n \"tests\": [\n {\n \"className\": \"YourClassName\",\n \"testMethods\": [\n \"testMethod1\",\n \"testMethod2\",\n \"testMethod3\"\n ]\n }\n ],\n \"maxFailedTests\": \"integer value\",\n \"testLevel\": \"TestLevel enum value\",\n \"skipCodeCoverage\": \"boolean value\"\n}\n",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/tooling/runTestsAsynchronous",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"tooling",
"runTestsAsynchronous"
]
},
"description": "Runs one or more methods within one or more Apex classes, using the asynchronous test execution mechanism. In the request body, you can specify test class names and IDs, suite names and IDs, the maximum number of failed tests to allow, and the test level, as comma-separated lists or as an array. You can also indicate whether to opt out of collecting code coverage information during the test run (available in API version 43.0 and later)."
},
"response": [
{
"name": "Tooling Run Tests Async",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"tests\": [\n {\n \"className\": \"PrepareSandboxTest\",\n \"testMethods\": [\n \"runApexClass_should_work\"\n ]\n }\n ],\n \"maxFailedTests\": \"1\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/tooling/runTestsAsynchronous",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"tooling",
"runTestsAsynchronous"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Date",
"value": "Mon, 11 Dec 2023 10:04:34 GMT"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=63072000; includeSubDomains"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-Robots-Tag",
"value": "none"
},
{
"key": "Cache-Control",
"value": "no-cache,must-revalidate,max-age=0,no-store,private"
},
{
"key": "Sforce-Limit-Info",
"value": "api-usage=250/15000"
},
{
"key": "Content-Type",
"value": "application/json;charset=UTF-8"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Transfer-Encoding",
"value": "chunked"
}
],
"cookie": [
],
"body": "\"7074H0000DCt2IZ\""
}
]
}