Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
forcedotcom avatar

Running Apex Tests

  • 2.5k installs
  • 763 repo stars
  • Updated July 24, 2026
  • forcedotcom/sf-skills

running-apex-tests is a Salesforce skill for Apex test execution, coverage analysis, and structured test-fix loops via sf apex run test.

About

Running Apex Tests guides Salesforce test execution, coverage analysis, and structured test-fix loops using sf apex run test workflows and a 120-point scoring rubric. It owns tasks involving Apex unit test failures, code coverage gaps, uncovered lines, and disciplined reruns while delegating production Apex authoring to generating-apex and LWC Jest work elsewhere. The workflow discovers test scope and factories, runs the smallest useful test set first, analyzes failures and stack traces, fixes code or tests, and widens regression only after stability. High-signal rules require SeeAllData=false, meaningful assertions, bulk tests with 251+ records, Test.startTest and stopTest for async, and factories or TestSetup for clarity. Gotchas cover SeeAllData org dependencies, uncommitted work pending on callout tests, mock setup order, and TestSetup re-query requirements. Reference files span CLI commands, test patterns, mocking, performance optimization, and agentic test-fix loops with parse-test-results hooks. Output reports test scope, pass or fail summary, coverage, root causes, and next steps.

  • sf apex run test scoped execution and coverage analysis.
  • Disciplined narrow-to-wide test-fix loop workflow.
  • SeeAllData=false and 251+ bulk record testing rules.
  • Mock callout and TestSetup gotcha resolution table.
  • 120-point scoring guide for test confidence quality.

Running Apex Tests by the numbers

  • 2,484 all-time installs (skills.sh)
  • +7 installs in the week ending Jul 28, 2026 (Skillselion tracking)
  • Ranked #331 of 2,184 Testing & QA skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
At a glance

running-apex-tests capabilities & compatibility

Capabilities
scoped sf apex run test execution · failure and stack trace analysis · coverage gap identification · bulk and async test pattern guidance · mock callout and testsetup troubleshooting · test fix loop with parse test results hook
Works with
salesforce
Use cases
testing · api development
Pricing
Free
From the docs

What running-apex-tests says it does

Test bulk behavior with 251+ records
SKILL.md
npx skills add https://github.com/forcedotcom/sf-skills --skill running-apex-tests

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs2.5k
repo stars763
Security audit3 / 3 scanners passed
Last updatedJuly 24, 2026
Repositoryforcedotcom/sf-skills

How do I run Apex tests, interpret failures, and raise coverage without flaky org-dependent tests?

Run Salesforce Apex tests, analyze coverage, and execute disciplined test-fix loops with sf apex run test workflows.

Who is it for?

Salesforce developers debugging Apex test failures, coverage drops, or bulk and async test scenarios.

Skip if: Skip for writing production Apex, Agentforce agent testing, or LWC Jest component tests.

When should I use this skill?

User runs Apex tests, checks code coverage, fixes failing Test.cls files, or manages test-fix loops.

What you get

Focused test run report with coverage percent, root-cause findings, and next rerun or fix recommendation.

  • Apex @IsTest class
  • Test Data Factory setup method

By the numbers

  • Targets 90%+ Apex code coverage
  • TestSetup creates 5 records via Test Data Factory by default

Files

SKILL.mdMarkdownGitHub ↗

running-apex-tests: 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 running-apex-tests 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 → generating-apex skill
  • testing Agentforce agents → testing-agentforce skill
  • testing LWC with Jest → generating-lwc-components

---

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 generating-apex 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

RuleRationale
Default to SeeAllData=falseEnsures test isolation; prevents reliance on org-specific data
Every test must assert meaningful outcomesTests with no assertions prove nothing and give false confidence
Test bulk behavior with 251+ recordsTriggers process in batches of 200; 251 records crosses the boundary
Use factories / @TestSetup when they improve clarityConsistent data creation in one place; rolled back between test methods
Pair Test.startTest() with Test.stopTest() for asyncEnsures async operations (queueable, future) complete before assertions
Do not hide flaky org dependencies inside testsPrevents intermittent failures tied to org state

---

Gotchas

IssueResolution
Test passes locally but fails in CI orgCheck for SeeAllData=true or undeclared dependencies on org-specific records
Coverage drops unexpectedly after refactorRun focused class-level tests first, then widen to RunLocalTests to confirm
"Uncommitted work pending" error in callout testDML and HTTP callouts cannot be mixed in the same test context without Test.startTest() wrapping
Mock not taking effect in testEnsure 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

NeedDelegate toReason
Fix production code or author test classesgenerating-apex skillCode generation and repair
Create bulk / edge-case test datahandling-sf-dataRealistic test datasets
Deploy updated tests to orgdeploying-metadataDeployment workflows
Inspect detailed runtime logsdebugging-apex-logsDeeper failure analysis

---

Reference File Index

FileWhen to read
references/cli-commands.mdAll sf apex run test command flags, output formats, async execution, and coverage commands
references/test-patterns.mdTest class templates — basic, bulk (251+), mock callout, and data factory patterns
references/testing-best-practices.mdCore testing principles — AAA pattern, naming conventions, bulk, negative, and mock strategies
references/test-fix-loop.mdAgentic test-fix loop implementation and failure analysis decision tree
references/mocking-patterns.mdHttpCalloutMock, DML mocking, StubProvider, and selector mocking patterns
references/performance-optimization.mdTechniques to reduce test execution time — DML mocking, SOQL mocking, loop optimizations
assets/basic-test.clsTemplate: standard test class with @TestSetup, positive / negative / bulk / edge-case methods
assets/bulk-test.clsTemplate: bulk test with 251+ records that crosses the 200-record trigger batch boundary
assets/mock-callout-test.clsTemplate: HTTP callout mock using HttpCalloutMock
assets/test-data-factory.clsTemplate: reusable TestDataFactory with create and insert helpers
assets/dml-mock.clsTemplate: IDML interface + DMLMock implementation for database-free unit tests
assets/stub-provider-example.clsTemplate: StubProvider-based dependency injection stub
hooks/scripts/parse-test-results.pyPost-tool hook — parses sf apex run test JSON output and formats failures for the auto-fix loop

---

Score Guide

ScoreMeaning
108+strong production-grade test confidence
96–107good test suite with minor gaps
84–95acceptable but strengthen coverage / assertions
< 84below standard; revise before relying on it

Related skills

Forks & variants (1)

Running Apex Tests has 1 known copy in the catalog totaling 485 installs. They canonicalize to this original listing.

FAQ

Why test with 251+ records?

Bulk tests should cross the 200-record trigger batch boundary to expose governor limit issues.

When is SeeAllData=true risky?

It ties tests to org-specific records and causes passes locally but failures in CI orgs.

How handle async queueable tests?

Wrap execution with Test.startTest and Test.stopTest so async work completes before assertions.

Is Running Apex Tests safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Testing & QAtestingbackend

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.