Help us improve
Share bugs, ideas, or general feedback.
From sf-skills
Runs Apex tests, analyzes coverage, and manages test-fix loops with 120-point scoring for Salesforce development.
npx claudepluginhub ccmalcom/sf-skills-plugin --plugin sf-skillsHow this skill is triggered — by the user, by Claude, or both
Slash command
/sf-skills:running-apex-testsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
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.
CREDITS.mdREADME.mdassets/basic-test.clsassets/bulk-test.clsassets/dml-mock.clsassets/mock-callout-test.clsassets/stub-provider-example.clsassets/test-data-factory.clshooks/scripts/parse-test-results.pyreferences/cli-commands.mdreferences/mocking-patterns.mdreferences/performance-optimization.mdreferences/test-fix-loop.mdreferences/test-patterns.mdreferences/testing-best-practices.mdGenerates and validates Apex test classes with TestDataFactory patterns, bulk testing (251+ records), mocking, and assertion best practices. Useful when creating new tests, improving coverage, or debugging failing tests.
Executes Apex tests against a connected sandbox org, parses results and coverage delta, identifies failures with stack traces, and suggests fixes.
Generates and runs unit, integration (testcontainers/docker-compose), and Playwright E2E test suites for JS/TS code. Analyzes coverage gaps with parallel test-generator agents, executes tests, and heals failures up to 3 times.
Share bugs, ideas, or general feedback.
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.
Use running-apex-tests when the work involves:
sf apex run test workflowsDelegate elsewhere when the user is:
generating-apex skilltesting-agentforce skillAsk for or infer:
Identify:
Start narrow when debugging a failure; widen only after the fix is stable.
Focus on:
When the issue is code or test quality:
generating-apex skill when neededCover:
| 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 |
| 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 |
When finishing, report in this order:
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>
| Need | Delegate to | Reason |
|---|---|---|
| Fix production code or author test classes | generating-apex skill | Code generation and repair |
| Create bulk / edge-case test data | handling-sf-data | Realistic test datasets |
| Deploy updated tests to org | deploying-metadata | Deployment workflows |
| Inspect detailed runtime logs | debugging-apex-logs | Deeper failure analysis |
| 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 tree |
references/mocking-patterns.md | HttpCalloutMock, DML mocking, StubProvider, and selector mocking patterns |
references/performance-optimization.md | Techniques to reduce test execution time — DML mocking, SOQL mocking, loop optimizations |
assets/basic-test.cls | Template: standard test class with @TestSetup, positive / negative / bulk / edge-case methods |
assets/bulk-test.cls | Template: bulk test with 251+ records that crosses the 200-record trigger batch boundary |
assets/mock-callout-test.cls | Template: HTTP callout mock using HttpCalloutMock |
assets/test-data-factory.cls | Template: reusable TestDataFactory with create and insert helpers |
assets/dml-mock.cls | Template: IDML interface + DMLMock implementation for database-free unit tests |
assets/stub-provider-example.cls | Template: StubProvider-based dependency injection stub |
hooks/scripts/parse-test-results.py | Post-tool hook — parses sf apex run test JSON output and formats failures for the auto-fix loop |
| Score | Meaning |
|---|---|
| 108+ | strong production-grade test confidence |
| 96–107 | good test suite with minor gaps |
| 84–95 | acceptable but strengthen coverage / assertions |
| < 84 | below standard; revise before relying on it |