Newer Version Available

This content describes an older version of this product. View Latest

Retrieve Unit Tests

The Test Discovery API returns details about Apex and automated flow tests. This resource is available in Tooling API version 65.0 and later.

Syntax

URI
/services/data/vXX.X/tooling/tests/
HTTPS Method
GET
Authentication
Authorization: Bearer token
Format
JSON
Request Query Parameters
Parameter Type Description
showAllMethods Boolean

Specifies whether to retrieve all methods (true) or only visible methods (false) in a test class.

If this parameter value isn’t specified, the default value is false.

Results adhere to standard Apex visibility rules, which are influenced by factors such as namespace, managed package origin, access modifiers, and user permissions. For example, if a test class is private, then it isn’t retrieved unless showAllMethods is set to true.

namespacePrefix String

Specifies the namespace to retrieve tests from. If this parameter value isn’t specified, tests in all namespaces are retrieved.

To query for only flow tests, set the namespacePrefix to "FlowTesting".

To query for flow tests in a namespaced package or org, use the syntax "FlowTesting.NamepacePrefix".

nextRecord String A cursor that specifies the first test class to retrieve in the next page of results. This value is included in the nextRecordUrl property of the current page.
pageSize Integer Specifies the number of test classes to retrieve per page. If this parameter value isn’t specified, the default value is 1000 classes. The maximum value is 10000 classes.
Request Body
None.
Response Body Properties
Name Type Description
apexTestClasses Object[] An array of Apex test class objects. If there aren’t any tests in the result set, the value is [].
size Integer The total number of test classes in the result set across all pages. If the result set is empty, the value is 0.
nextRecordsUrl String The URL of the next page in the result set. If the current page is the last page in a result set, the nextRecordsUrl value is null.
testSetSignature String

An MD5 hash that represents the test classes and methods in the result set. If there aren’t any tests in the result set, the value is "".

When a result set spans multiple pages, the testSetSignature can change from one page to the next. A different testSetSignature indicates that the tests in the result set have changed since the retrieval of the previous page.

message String An informational message about the request, such as an input validation warning, or null if there is no applicable message.
Each Apex test class object in the apexTestClasses list includes these properties.
Name Type Description
id String

The Salesforce ID of the test class.

All Apex test classes have an ID.

Not all flow test classes have an ID. If the flow test class doesn’t have an ID, then the id value is "".

name String

The name of the test class.

For a flow test, the name is the API name of the flow.

namespacePrefix String

The namespace of the test class.

Apex tests are in the default namespace. If an Apex test is in a namespaced package or org, the namespacePrefix value is "NamepacePrefix". Otherwise, the namespacePrefix value is "".

All flow tests are in the FlowTesting namespace. If a flow test is in a namespaced package or org, the namespacePrefix value is "FlowTesting.NamepacePrefix". Otherwise, the namespacePrefix value is "FlowTesting".

testMethods Object[]

An array of test methods in the test class.

Each test method object includes the name property, which is set to the name of the test method. For example, {"name": "testSimpleAddition"}.

A flow test method name includes the API name of the flow followed by an underscore (_) and the API name of the flow test. For example, {"name":"FlowName_UpdateRecordFlowTest"}

Example

Example Request
1https://MyDomain.my.salesforce.com/services/data/v65.0/tooling/tests?namespacePrefix=my_namespace&pageSize=2
Example Response Body
1{
2  "apexTestClasses":[
3    {
4      "id":"01pxx0000004UVl",
5      "name":"BAAdditionTest",
6      "namespacePrefix":"my_namespace",
7      "testMethods":[
8        {"name":"testNegativeAddition"},
9        {"name":"testSimpleAddition"}
10      ]
11    },
12    {
13      "id":"01pxx0000004UXN",
14      "name":"BABitwiseTest",
15      "namespacePrefix":"my_namespace",
16      "testMethods":[
17        {"name":"testBitwiseAND"},
18        {"name":"testBitwiseOR"}
19      ]
20    }
21  ],
22  "message":null,
23  "nextRecordsUrl":"/services/data/v65.0/tooling/tests?namespacePrefix=my_namespace&pageSize=2&nextRecord=my_namespace.BAComparisonTest",
24  "size":10,
25  "testSetSignature":"91a678b54197669171f11eb824d6765a"
26}
27