/platform-apex-test-run
Apex test execution, coverage analysis, and test-fix loops with 120-point scoring. Use when the user needs to run Apex tests, check code coverage, fix failing tests, or work with *Test.cls / *_Test.cls files. TRIGGER when: user runs Apex tests, checks code coverage, fixes
$ npx -y skills add forcedotcom/sf-skills --skill platform-apex-test-run --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/platform-apex-test-run
Context preview
The summary Claude sees to decide when to auto-load this skill.
Apex test execution, coverage analysis, and test-fix loops with 120-point scoring. Use when the user needs to run Apex tests, check code coverage, fix failing tests, or work with *Test.cls / *_Test.cls files. TRIGGER when: user runs Apex tests, checks code coverage, fixes
SKILL.md
platform-apex-test-run.SKILL.mdname: platform-apex-test-run
description: "Apex test execution, coverage analysis, and test-fix loops with 120-point scoring. Use when the user needs to run Apex tests, check code coverage, fix failing tests, or work with *Test.cls / *_Test.cls files. TRIGGER when: user runs Apex tests, checks code coverage, fixes failing tests, or touches *Test.cls / *_Test.cls files. DO NOT TRIGGER when: writing Apex production code (use platform-apex-generate), Agentforce agent testing (use agentforce-test), or Jest/LWC tests (use experience-lwc-generate)."
metadata:
cliTools:
- tool: ["jq"]
semver: ">=1.6.0"
- tool: ["python3"]
semver: ">=3.10.0"
- tool: ["sf"]
semver: ">=2.0.0"
relatedSkills:
- "agentforce-test"
- "experience-lwc-generate"
- "platform-apex-generate"
- "platform-apex-logs-debug"
- "platform-data-manage"
- "platform-metadata-deploy"
version: "1.1"platform-apex-test-run: Salesforce Test Execution & Coverage Analysis
Use this skill when the user needs **Apex test execution and failure analysis**: running tests, checking coverage, interpreting failures, improving coverage, and managing a disciplined test-fix loop for Salesforce code.
When This Skill Owns the Task
Use `platform-apex-test-run` when the work involves:
- `sf apex run test` workflows
- Apex unit-test failures
- code coverage analysis
- identifying uncovered lines and missing test scenarios
- structured test-fix loops for Apex code
Delegate elsewhere when the user is:
- writing or refactoring production Apex → `platform-apex-generate` skill
- testing Agentforce agents → `agentforce-test` skill
- testing LWC with Jest → [experience-lwc-generate](../experience-lwc-generate/SKILL.md)
---
Required Context to Gather First
Ask for or infer:
- target org alias
- desired test scope: single class, specific methods, suite, or local tests
- coverage threshold expectation
- whether the user wants diagnosis only or a test-fix loop
- whether related test data factories already exist
---
Recommended Workflow
1. Discover test scope
Identify:
- existing test classes
- target production classes
- test data factories / setup helpers
2. Run the smallest useful test set first
Start narrow when debugging a failure; widen only after the fix is stable.
3. Analyze results
Focus on:
- failing methods
- exception types and stack traces
- uncovered lines / weak coverage areas
- whether failures indicate bad test data, brittle assertions, or broken production logic
4. Run a disciplined fix loop
When the issue is code or test quality:
- delegate code fixes to `platform-apex-generate` skill when needed
- add or improve tests
- rerun focused tests before broader regression
5. Improve coverage intentionally
Cover:
- positive path
- negative / exception path
- bulk path (251+ records where appropriate)
- callout or async path when relevant
---
High-Signal Rules
| Rule | Rationale | |------|-----------| | Default to `SeeAllData=false` | Ensures test isolation; prevents reliance on org-specific data | | Every test must assert meaningful outcomes | Tests with no assertions prove nothing and give false confidence | | Test bulk behavior with 251+ records | Triggers process in batches of 200; 251 records crosses the boundary | | Use factories / `@TestSetup` when they improve clarity | Consistent data creation in one place; rolled back between test methods | | Pair `Test.startTest()` with `Test.stopTest()` for async | Ensures async operations (queueable, future) complete before assertions | | Do not hide flaky org dependencies inside tests | Prevents intermittent failures tied to org state |
---
Gotchas
| Issue | Resolution | |-------|------------| | Test passes locally but fails in CI org | Check for `SeeAllData=true` or undeclared dependencies on org-specific records | | Coverage drops unexpectedly after refactor | Run focused class-level tests first, then widen to `RunLocalTests` to confirm | | "Uncommitted work pending" error in callout test | DML and HTTP callouts cannot be mixed in the same test context without `Test.startTest()` wrapping | | Mock not taking effect in test | Ensure `Test.setMock()` is called before the code that makes the callout | | `@TestSetup` data missing in test method | `@TestSetup` data is committed per test method — re-query it; do not store in static variables |
---
Output Format
When finishing, report in this order: 1. **What tests were run** 2. **Pass/fail summary** 3. **Coverage result** 4. **Root-cause findings** 5. **Fix or next-run recommendation**
Suggested shape:
Test run: <scope>
Org: <alias>
Result: <passed / partial / failed>
Coverage: <percent / key classes>
Issues: <highest-signal failures>
Next step: <fix class, add test, rerun scope, or widen regression>
---
Cross-Skill Integration
| Need | Delegate to | Reason | |------|-------------|--------| | Fix production code or author test classes | `platform-apex-generate` skill | Code generation and repair | | Create bulk / edge-case test data | [platform-data-manage](../platform-data-manage/SKILL.md) | Realistic test datasets | | Deploy updated tests to org | [platform-metadata-deploy](../platform-metadata-deploy/SKILL.md) | Deployment workflows | | Inspect detailed runtime logs | [platform-apex-logs-debug](../platform-apex-logs-debug/SKILL.md) | Deeper failure analysis |
---
Reference File Index
| File | When to read | |------|-------------| | `references/cli-commands.md` | All `sf apex run test` command flags, output formats, async execution, and coverage commands | | `references/test-patterns.md` | Test class templates — basic, bulk (251+), mock callout, and data factory patterns | | `references/testing-best-practices.md` | Core testing principles — AAA pattern, naming conventions, bulk, negative, and mock strategies | | `references/test-fix-loop.md` | Agentic test-fix loop implementation and failure analysis decision
Read more
name: platform-apex-test-run
description: "Apex test execution, coverage analysis, and test-fix loops with 120-point scoring. Use when the user needs to run Apex tests, check code coverage, fix failing tests, or work with *Test.cls / *_Test.cls files. TRIGGER when: user runs Apex tests, checks code coverage, fixes failing tests, or touches *Test.cls / *_Test.cls files. DO NOT TRIGGER when: writing Apex production code (use platform-apex-generate), Agentforce agent testing (use agentforce-test), or Jest/LWC tests (use experience-lwc-generate)."
metadata:
cliTools:
- tool: ["jq"]
semver: ">=1.6.0"
- tool: ["python3"]
semver: ">=3.10.0"
- tool: ["sf"]
semver: ">=2.0.0"
relatedSkills:
- "agentforce-test"
- "experience-lwc-generate"
- "platform-apex-generate"
- "platform-apex-logs-debug"
- "platform-data-manage"
- "platform-metadata-deploy"
version: "1.1"platform-apex-test-run: Salesforce Test Execution & Coverage Analysis
Use this skill when the user needs **Apex test execution and failure analysis**: running tests, checking coverage, interpreting failures, improving coverage, and managing a disciplined test-fix loop for Salesforce code.
When This Skill Owns the Task
Use `platform-apex-test-run` when the work involves:
- `sf apex run test` workflows
- Apex unit-test failures
- code coverage analysis
- identifying uncovered lines and missing test scenarios
- structured test-fix loops for Apex code
Delegate elsewhere when the user is:
- writing or refactoring production Apex → `platform-apex-generate` skill
- testing Agentforce agents → `agentforce-test` skill
- testing LWC with Jest → [experience-lwc-generate](../experience-lwc-generate/SKILL.md)
---
Required Context to Gather First
Ask for or infer:
- target org alias
- desired test scope: single class, specific methods, suite, or local tests
- coverage threshold expectation
- whether the user wants diagnosis only or a test-fix loop
- whether related test data factories already exist
---
Recommended Workflow
1. Discover test scope
Identify:
- existing test classes
- target production classes
- test data factories / setup helpers
2. Run the smallest useful test set first
Start narrow when debugging a failure; widen only after the fix is stable.
3. Analyze results
Focus on:
- failing methods
- exception types and stack traces
- uncovered lines / weak coverage areas
- whether failures indicate bad test data, brittle assertions, or broken production logic
4. Run a disciplined fix loop
When the issue is code or test quality:
- delegate code fixes to `platform-apex-generate` skill when needed
- add or improve tests
- rerun focused tests before broader regression
5. Improve coverage intentionally
Cover:
- positive path
- negative / exception path
- bulk path (251+ records where appropriate)
- callout or async path when relevant
---
High-Signal Rules
| Rule | Rationale | |------|-----------| | Default to `SeeAllData=false` | Ensures test isolation; prevents reliance on org-specific data | | Every test must assert meaningful outcomes | Tests with no assertions prove nothing and give false confidence | | Test bulk behavior with 251+ records | Triggers process in batches of 200; 251 records crosses the boundary | | Use factories / `@TestSetup` when they improve clarity | Consistent data creation in one place; rolled back between test methods | | Pair `Test.startTest()` with `Test.stopTest()` for async | Ensures async operations (queueable, future) complete before assertions | | Do not hide flaky org dependencies inside tests | Prevents intermittent failures tied to org state |
---
Gotchas
| Issue | Resolution | |-------|------------| | Test passes locally but fails in CI org | Check for `SeeAllData=true` or undeclared dependencies on org-specific records | | Coverage drops unexpectedly after refactor | Run focused class-level tests first, then widen to `RunLocalTests` to confirm | | "Uncommitted work pending" error in callout test | DML and HTTP callouts cannot be mixed in the same test context without `Test.startTest()` wrapping | | Mock not taking effect in test | Ensure `Test.setMock()` is called before the code that makes the callout | | `@TestSetup` data missing in test method | `@TestSetup` data is committed per test method — re-query it; do not store in static variables |
---
Output Format
When finishing, report in this order: 1. **What tests were run** 2. **Pass/fail summary** 3. **Coverage result** 4. **Root-cause findings** 5. **Fix or next-run recommendation**
Suggested shape:
Test run: <scope> Org: <alias> Result: <passed / partial / failed> Coverage: <percent / key classes> Issues: <highest-signal failures> Next step: <fix class, add test, rerun scope, or widen regression>
---
Cross-Skill Integration
| Need | Delegate to | Reason | |------|-------------|--------| | Fix production code or author test classes | `platform-apex-generate` skill | Code generation and repair | | Create bulk / edge-case test data | [platform-data-manage](../platform-data-manage/SKILL.md) | Realistic test datasets | | Deploy updated tests to org | [platform-metadata-deploy](../platform-metadata-deploy/SKILL.md) | Deployment workflows | | Inspect detailed runtime logs | [platform-apex-logs-debug](../platform-apex-logs-debug/SKILL.md) | Deeper failure analysis |
---
Reference File Index
| File | When to read | |------|-------------| | `references/cli-commands.md` | All `sf apex run test` command flags, output formats, async execution, and coverage commands | | `references/test-patterns.md` | Test class templates — basic, bulk (251+), mock callout, and data factory patterns | | `references/testing-best-practices.md` | Core testing principles — AAA pattern, naming conventions, bulk, negative, and mock strategies | | `references/test-fix-loop.md` | Agentic test-fix loop implementation and failure analysis decision
This repository provides a curated collection of Salesforce agent skills for building applications.
Repo: forcedotcom/sf-skills
Other skills on sf-skills.
- /agentforce-generate
Build, modify, optimize, debug, and deploy agents with Agentforce Agent Script. TRIGGER when: user creates, modifies, optimizes, or asks about .agent files or aiAuthoringBundle metadata; changes agent behavior, responses, or conversation logic; designs agent actions, tools,
Open skill - /agentforce-observe
Analyze production Agentforce agent behavior using session traces and Data Cloud. TRIGGER when: user queries STDM session data or Data Cloud trace records; investigates production agent failures, regressions, or performance issues; asks about session traces, conversation logs,
Open skill - /agentforce-test
Write, run, and analyze structured test suites for Agentforce agents — functional AND security. TRIGGER when: user writes or modifies test spec YAML (AiEvaluationDefinition); runs sf agent test create, run, run-eval, or results commands; asks about test coverage strategy, metric
Open skill - /automation-flow-generate
Generate Salesforce Flows using the MCP tool execute_metadata_action. Use when the user asks to create, build, or generate a flow — including Screen, Autolaunched, Record-Triggered (before/after-save), Scheduled. Also trigger for flow-like requests such as \"when a record is
Open skill - /dx-code-analyzer-configure
Set up, configure, and troubleshoot Salesforce Code Analyzer for any project. Handles installation, prerequisite checks, diagnosing broken setups, creating and editing code-analyzer.yml overrides, engine-specific settings, ignore patterns, severity overrides, and CI/CD pipeline
Open skill - /dx-code-analyzer-custom-rule-create
Create custom Code Analyzer rules for Regex (pattern matching), PMD (XPath/AST for Apex and metadata XML), and ESLint (LWC/JavaScript/TypeScript). Use when users want to enforce coding standards, ban patterns, detect hardcoded values, govern metadata, or add rules not in the
Open skill

