ApexTestSuite defines a reusable group of Apex test classes to include in a test run. It controls class selection, not test implementation: the test code remains in separate ApexClass components.
A suite can select classes by explicit name or wildcard pattern, including tests from specified namespaces. A wildcard inside the suite selects test classes; a wildcard under ApexTestSuite in package.xml selects suite components.
Key Elements
| Element | What the Element Controls |
|---|---|
testClassName |
A repeated string element identifying test classes to include. Supports explicit class names, patterns such as A*Class, * for all local tests, and namespace-qualified selections such as Namespace1.NamespacedTestClass or Namespace1.*. |
Behavior and Constraints
Each testClassName entry contributes a class selection to the suite:
-
LocalTestClassselects that local test class. -
A*Classselects matching class names, such asAClass,AnotherClass, andAwesomeClass. -
*selects all local tests. -
Namespace1.NamespacedTestClassselects a specific test class inNamespace1. -
Namespace1.*selects all tests inNamespace1.
Local tests are tests in the org that do not originate from managed packages. A suite containing only * therefore does not include every test in an org that also contains managed-package tests.
To include namespaced tests, specify each namespace individually, using a dot between the namespace and the class name or wildcard. For example, selecting all tests in two namespaces requires separate Namespace1.* and Namespace2.* entries.
A wildcard entry represents a selection of classes, not a single class dependency. The matching classes available in an org matter when interpreting the suite's scope; the same pattern can select different classes in different orgs.
Deployment and Retrieval
ApexTestSuite supports retrieval and deployment through the Metadata API. Components use the .testSuite suffix and reside in the testSuites folder. The Salesforce metadata reference documents the component format and manifest selections.
In package.xml, use ApexTestSuite as the type name. Specify suite names such as Suite1 and Suite2 as members, or use * to select all suite components.
If the suite's test classes already exist in the target org, you can omit ApexClass from package.xml. Otherwise, the required class definitions must also be made available in the target org. Deploying a suite does not supply the code for its selected classes.
Keep the two wildcard scopes separate: * in a suite's testClassName selects local test classes, while * in the manifest's ApexTestSuite members selects suites.
Relationships
The suite connects to test implementations through class names and class-selection patterns. An explicit name identifies a class, while a wildcard can select multiple matching classes.
References
-
ApexClass:testClassName.
Reported Issues
-
A local file path can cause a suite lookup failure. A 2022 report involving
sfdx force:apex:test:runpassed a local.testSuite-meta.xmlpath to the suite option. The answer advised deploying the suite to the target org first, then selecting it by suite name rather than file path, because execution occurs on Salesforce's servers. See the suite execution discussion. -
JSON command output did not satisfy the result-format requirement for code coverage. In the same 2022 discussion, a command using
-cand--jsonfailed because it lacked a separate result-format option. The answer advised adding-ror--resultFormatwithhuman,tap,junit, orjson. See the coverage format explanation.
Common Questions
Does an ApexTestSuite containing * run managed-package tests?
No. * selects local tests, which exclude tests originating from managed packages. Add a namespace-qualified entry, such as Namespace1.*, for each namespace you want to include.
Do I need to deploy ApexClass with ApexTestSuite?
You can omit ApexClass from the manifest when the selected test classes already exist in the target org. Otherwise, their definitions must also be made available; the suite contains class selections, not class code.
How do I retrieve all ApexTestSuite components?
Use * as the member selection for ApexTestSuite in package.xml. This selects suite components, not the test classes selected inside those suites.
Why does CLI execution fail when I pass a test suite file path?
A reported failure occurred because the suite option treated the path as a suite lookup value. The reported correction was to deploy the suite to the target org and select it by suite name instead of its local file path.