sf-apex-testing

Write and refactor Salesforce Apex test classes with mocks and bulk scenarios.

13|2|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/jiten-singh-shahi/salesforce-claude-code --skill sf-apex-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sf-apex-testing
Source: https://github.com/jiten-singh-shahi/salesforce-claude-code/tree/main/.cursor/skills/sf-apex-testing
Command: npx skills add https://github.com/jiten-singh-shahi/salesforce-claude-code --skill sf-apex-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps Salesforce developers create well-structured Apex unit tests that increase code coverage, catch governor limit issues, and reduce deployment failures due to insufficient tests.

Core Features & Use Cases

  • Test structure & naming: Enforces Arrange-Act-Assert patterns and standardized test method names for readability and maintainability.
  • TestDataFactory & TestSetup: Promotes centralized factory classes and TestSetup usage to produce consistent data and isolated transactions across tests.
  • Governor limit and async testing: Covers bulk-trigger scenarios, Queueable/@future execution, and use of Test.startTest/Test.stopTest to validate limits and asynchronous behavior.
  • Mocks and stubs: Shows HttpCalloutMock, multi-callout mock patterns, and System.createStub usage for dependency injection and deterministic tests.
  • Coverage strategy: Advises branch testing, use of @testFor and RunRelevantTests when available, and practical approaches to reach target coverage thresholds.

Quick Start

Ask the sf-apex-testing skill to audit a failing deployment and generate concrete test methods, factory patterns, and mock implementations to raise coverage and verify governor-limit behavior.

Frequently Asked Questions about sf-apex-testing

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

FAQPage Schema
How do I write Apex unit tests that avoid hitting Salesforce governor limits?

To write Apex unit tests that avoid governor limits, use Test.startTest and Test.stopTest to isolate asynchronous execution and bulk scenarios. Testing with large record counts validates that triggers respect Salesforce transaction limits.

What is a TestDataFactory pattern in Apex and when should I use it?

A TestDataFactory pattern in Apex is a centralized class that generates consistent test records. You should use it with TestSetup annotations to ensure isolated transactions and maintainable test data across all unit tests.

How do I mock HTTP callouts in Apex test classes?

Mock HTTP callouts in Apex test classes by implementing the HttpCalloutMock interface or using System.createStub patterns. These mocks inject deterministic responses, allowing tests to run without making live external network requests.

Can I test Queueable and future methods in Salesforce deployments?

Yes, you can test Queueable and future methods in Salesforce deployments by wrapping the asynchronous call between Test.startTest and Test.stopTest. This ensures the async job executes synchronously within the test context.

What's the best way to increase Apex code coverage for CI pipelines?

The best way to increase Apex code coverage for CI pipelines is to enforce branch testing with assertions and Arrange-Act-Assert patterns. Using RunRelevantTests and centralized test factories ensures reliable coverage thresholds.

Why do my Apex deployment tests fail in production but pass in sandbox?

Apex deployment tests fail in production but pass in sandbox when test data lacks isolation or misses bulk scenarios. Using TestSetup and mocking callouts with HttpCalloutMock ensures deterministic tests independent of environment data.