sf-testing

Runs Apex tests, analyzes code coverage, and automates test-fix loops via Salesforce CLI.

1|Updated May 7, 2026
One-click install
npx skills add https://github.com/amanpraaj/sf-skill-hub --skill sf-testing-amanpraaj
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sf-testing
Source: https://github.com/amanpraaj/sf-skill-hub/tree/main/skills/salesforce/sf-testing
Command: npx skills add https://github.com/amanpraaj/sf-skill-hub --skill sf-testing-amanpraaj

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve? Running Apex tests, interpreting failures, and reaching required code coverage thresholds in Salesforce orgs is slow and error-prone when done manually. This Skill automates test execution through the sf CLI, parses results and coverage reports, diagnoses root causes of failures, and drives a disciplined test-fix loop until tests pass. ## Core Features & Use Cases - Test Execution & Coverage Analysis: Run single classes, specific methods, suites, or all local tests with sf apex run test, then parse JSON results for pass/fail summaries and per-class coverage percentages. - Failure Diagnosis & Auto-Fix Loop: Classify failures (AssertException, NullPointerException, DmlException, LimitException) and delegate code fixes to sf-apex, re-running tests until passing or max iterations. - Testing Patterns & Mocking Guidance: Reference guides for HttpCalloutMock, DML mocking, StubProvider, test data factories, bulk testing with 251+ records, and performance optimization. - Use Case: A developer asks to run all local tests with coverage on a sandbox; the Skill executes the run, reports 82% coverage with two NullPointerException failures, identifies missing null checks, applies fixes, and re-runs the failing methods to confirm green results. ## Quick Start Ask the agent to run all local Apex tests with code coverage against your target org alias and report failures with suggested fixes.

Frequently Asked Questions about sf-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run Apex tests with code coverage using sf CLI?▼

Run `sf apex run test --class-names MyTest --code-coverage --result-format json --target-org your-alias` to execute a test class with coverage. Use `--test-level RunLocalTests` to run all tests except managed packages, and `--output-dir` to save results for parsing.

How do I fix failing Apex tests automatically?▼

The agentic test-fix loop parses failure messages, classifies the error type such as NullPointerException or DmlException, identifies the root cause, delegates the code fix to the sf-apex skill, and re-runs the failing test. It iterates up to three attempts until tests pass.

What code coverage is required for Salesforce deployment?▼

Salesforce requires a minimum of 75% org-wide Apex coverage for production deployment. Best practice targets 90% or higher overall, with 100% coverage on business-critical code paths.

How do I test HTTP callouts in Apex?▼

Salesforce blocks real HTTP requests in tests, so you must implement the HttpCalloutMock interface and register it with Test.setMock before invoking the callout. The mock returns a predefined HttpResponse with your chosen status code and body.

Why should Apex tests use 251 records for bulk testing?▼

Triggers process records in batches of 200, so testing with 251 records crosses the batch boundary and exposes bulkification bugs like DML or SOQL inside loops. It also verifies the code stays within governor limits across multiple batches.

When should I not use this Apex testing skill?▼

Use sf-apex when writing or refactoring production Apex code rather than running tests. Use sf-ai-agentforce-testing for Agentforce agent testing and sf-lwc for Jest-based Lightning Web Component tests, as those fall outside Apex test execution scope.