/apex-test-list:annotate-testsfrom apex-test-list
Maps Apex classes and triggers to their tests in Salesforce DX projects, writing // @Tests: annotations for use with the apextestlist plugin. Proposes mappings from org code coverage or static analysis, then writes reviewable source comments.
Ships in apex-test-list. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The apextestlist plugin reads // @Tests: and // @TestSuites: comments in
Apex classes and triggers, and sf apextests list turns the changed files into
a --tests list for sf project deploy start --test-level RunSpecifiedTests.
This skill writes those comments. Every mapping lives in the source, so the
team can review it in a pull request and see exactly which tests a deploy runs.
The apex-test-map command does the scanning and file edits, so large
projects don't have to be read file by file. It ships in the apextestlist npm
package, and npx -y -p apextestlist@1 apex-test-map runs it without the Salesforce
CLI or a plugin install. It needs Node.js 22.19 or newer and changes files only
in apply.
apextestlist reads annotations with /@tests\s*:\s*([^/\n]+)/gi:
// line comments: // @Tests: AccountServiceTest, AccountTriggerTest.
A name ends at a / or the end of the line, so never put annotations inside
a /* ... */ block on one line, and never add trailing comments after them.@Tests: keyword is
case-insensitive.@Tests: lines in one file are combined.@isTest) are always selected when they
change and need no annotation.sfdx-project.json in the working directory or a parent. If there is
none, stop: this only works in a Salesforce DX project. Run commands from
the folder that holds it.node --version is 22.19 or newer.--ignore-package-directory <path>.git status --porcelain -- '*.cls' '*.trigger').
If there are any, tell the user, so their edits and the annotations stay
distinguishable in the diff.// @Tests: lines at the top of each file.A header template is a comment that every Apex file should start with. Look
for one first: a file the user names, a template in the repository (often
under config/), or the header most classes already share. If there is none
and the user wants one, write it with them and save it in the repository, for
example config/apex-header.txt, so the whole team uses the same file:
/**
* @description {{name}}
* @Tests: {{tests}}
* @TestSuites: {{suites}}
*/
{{name}} (class or trigger name), {{kind}} (class or
trigger), {{tests}}, and {{suites}}. Nothing else is filled in; write
other tags such as @author as fixed text, or leave them out. Never guess an
author or a date.{{tests}} must end its @Tests: line, and {{suites}} its @TestSuites:
line, with no */ after them, because apextestlist reads to the end of the
line. The command checks this and stops with an explanation if not.@TestSuites: line.With --header-template <file>, apply:
@Tests: or @TestSuites: line the file already has;It never rewrites an existing header to match the template. If the user wants that, treat it as a separate change with its own review, not part of annotating tests.
Org code coverage gives the real class-to-test map, including indirect coverage that static analysis can't see. Ask whether the user has an org with the project's code deployed and recent test results, and its alias. Prefer a full sandbox or scratch org. Never run tests in production without the user asking.
Coverage per test class lives in ApexCodeCoverage. It holds data only after
tests ran asynchronously, and recompiling Apex can clear it. If it's empty or
stale, ask before running the tests, because a full run can take a long time:
sf apex run test --test-level RunLocalTests --code-coverage --wait 120 --target-org <alias>
Then export it:
sf data query --use-tooling-api --json --target-org <alias> \
--query "SELECT ApexTestClass.Name, ApexClassOrTrigger.Name FROM ApexCodeCoverage" \
> <temp folder>/coverage.json
Write the file to a temporary folder outside the project. Large orgs can
exceed the CLI's 10,000-record default; if the result reports more records than
it returned, ask the user to raise it with sf config set org-max-query-limit=<n>
and query again.
If there's no org, skip this step. Tell the user the mappings will come from static analysis only, and that they miss indirect coverage.
npx -y -p apextestlist@1 apex-test-map scan [--coverage <temp folder>/coverage.json] [--missing-only] [--only Name1,Name2]
Use --missing-only for a first pass on a project that already has some
annotations, and --only for a few classes. Add --json if you need to
process the output further.
Each class or trigger gets proposed tests, each tagged with where it came from:
| Source | Meaning | Trust |
|---|---|---|
coverage | the test executed lines of this class in the org | high |
name | naming convention: FooTest, Foo_Test, FooTests, TestFoo, Test_Foo | high |
handler | (triggers) a test of a class the trigger calls, such as its handler | high |
reference | the test's code names the class (comments and strings ignored) | medium: may be setup only |
For triggers, the scan also lists tests that run DML on the trigger's object. Those fire the trigger, but there are usually too many to annotate. Don't propose them unless they're clearly about the trigger's behavior, or coverage confirms them.
Decide the tests for each class with judgment, not just by copying every proposal:
coverage, name, and handler tests. Keep reference tests whose
test methods exercise the class, and drop ones that only use it for setup
(for example a data factory or utility).@TestSuites: instead.grep for the class name in non-test classes) and
suggest those callers' tests, or report them as untested.Show the user the plan as a table (class, tests, why) before writing anything. For many classes, summarize and list only the uncertain ones. Then write it to a temporary file outside the project:
{
"AccountService": ["AccountServiceTest"],
"trigger:AccountTrigger": ["AccountTriggerHandlerTest"],
"OpportunitySelector": { "tests": ["OpportunityServiceTest"], "suites": ["SalesSuite"] }
}
Keys are class or trigger names. Prefix a key with trigger: or class: when
a class and a trigger share a name.
Preview, then write:
npx -y -p apextestlist@1 apex-test-map apply --plan <temp folder>/plan.json --dry-run
npx -y -p apextestlist@1 apex-test-map apply --plan <temp folder>/plan.json
Add --header-template <file> to both commands when the project uses one.
apply checks the whole plan first and changes nothing if any name is not a
local test class or suite (--allow-unknown allows org-only tests). It merges
new names into the first existing annotation, adds a missing one on the next
line with the same comment prefix, and otherwise adds a // @Tests: line at the
top of the file (or follows the header template). It keeps the file's line
endings. Running it twice changes nothing.
npx -y -p apextestlist@1 apex-test-map audit and fix anything it reports about the new annotations.npx -y -p apextestlist@1 apex-test-map list --ignore-missing-tests and
show the user the list it produces. It uses the same selection logic as
sf apextests list, without the Salesforce CLI.git diff --stat and suggest committing the annotations on their own,
separate from functional changes.Changes to flows, fields, objects, or validation rules don't touch an Apex
file, so @Tests: can't select tests for them. For those, apextestlist reads
.test-dependencies.yml in the project root when run with
--manifest package.xml --filter-by-metadata. See
references/test-dependencies.md to build it.
Only do this if the user asks for it or deploys these changes with a manifest.
Summarize: how many files were annotated, which mappings came from coverage
versus static analysis, classes left without tests, and broad mappings worth a
suite. Remind the user that selecting tests per change can miss side effects
(trigger cascades, flows calling Apex), so a periodic full RunLocalTests run
is still worth keeping, and that the audit-tests skill finds annotations that
go stale over time.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub wisefoxme/apex-test-list --plugin apex-test-list2 skills in this plugin
Other plugins' skills for the same job