How to control which Apex tests run on a full deploy
Narrow a full deploy's Apex test run to a curated suite or a class list. For why a curated suite exists and how it relates to delta deploys, see curated test suites vs RunRelevantTests.
Delta deploys have their own test level
The delta leg runs RunRelevantTests unless the DELTA_TEST_LEVEL repository variable names
another level; only then do the flags and variables below apply to it, resolved like a full
deploy (DELTA_TEST_LEVEL).
Know the default
Unless told otherwise, deploy / deploy validate run RunLocalTests. Override it per run with
--test-level (alias --testlevel), or set it once for an environment with the TEST_LEVEL
repository variable — the flag wins if both are present.
Generate a curated test suite
A curated suite is a fixed, named list of test classes stored as metadata. Build one from a source directory:
-d/--source-dir(required) — where to scan for@isTestclasses.-n/--name(required) — the suite name; the files are written toforce-app/main/default/testSuites/<name>_<n>.testSuite-meta.xml, split at 190 classes per file. The deploy andtest apexcommands pick up every part of a suite by its name.--ignore-path(optional) — a gitignore-style file listing classes to leave out. The template ships.testsuiteignoreCifor this purpose.
Re-running the command overwrites the suite files with the current class list.
To make the suite part of the project's standing set, add it to
config/project-test-suites-config.json (name, ignorePath, optOutKey) and regenerate all
listed suites at once:
Commit the suite
The generated *.testSuite-meta.xml is ordinary metadata — commit it like any other force-app file
so the suite deploys with the rest of the project and CI can reference it by name.
Keep the suite fresh on Apex commits
A committed suite goes stale the moment a new Apex test class is added and nobody regenerates it. The
pre-commit step that would regenerate CiTestSuite from staged Apex classes ships opted out —
remove createapextestsuiteprecommit from .opt-out to have it regenerate on every Apex commit (see
opt-out keys). If you keep it opted out, run
npm run apex:testsuite:generate:configured whenever the class list changes.
Deploy with the suite
Point a full deploy at the suite by name:
--test-suite-names (or the TEST_SUITE_NAMES repository variable) takes the suite name. Nothing
further to do — the orchestrator resolves the suite to its class list automatically whenever
--test-suite-names (or TEST_SUITE_NAMES) is set (see curated test suites vs
RunRelevantTests
for how).
Run a raw class list instead
Skip the suite file entirely and name classes directly:
Space-separate multiple classes in --tests (or the TESTS repository variable). Setting --tests
forces the effective test level to RunSpecifiedTests, regardless of what --test-level was set to.
Long class lists on Windows
On Windows the sf CLI runs through its sf.cmd shim, whose command line is capped at 8191
characters; a --tests list of a few hundred classes exceeds it. Linux CI is unaffected.
Locally, run a suite (--suite-names) instead of a long class list.