sf-apex-testing

Writes and repairs Salesforce Apex unit tests with mocks, async recipes, and coverage gates.

2|Updated Sep 12, 2026
One-click install
npx skills add https://github.com/grzmol/vibe-force --skill sf-apex-testing-grzmol
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sf-apex-testing
Source: https://github.com/grzmol/vibe-force/tree/main/skills/sf-apex-testing
Command: npx skills add https://github.com/grzmol/vibe-force --skill sf-apex-testing-grzmol

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Apex deployments fail when tests are missing, coverage falls below the 75% platform minimum, or tests are flaky and org-data dependent. This Skill provides the patterns and rules needed to write deterministic, bulk-safe Apex tests that pass coverage gates and survive deployment to production. ## Core Features & Use Cases - Test authoring patterns: @IsTest classes, @TestSetup, Test.startTest/Test.stopTest limit contexts, the modern Assert class, test data factories, builders, and Test.loadData with static resources. - Mocking and async testing: HttpCalloutMock, StaticResourceCalloutMock, WebServiceMock, the Stub API, plus deterministic recipes for Queueable, Batch, future, Schedulable, and platform events. - Coverage and gate enforcement: Explains the 75% platform rule, per-class coverage under RunSpecifiedTests, sf apex run test flag selection, and how vf-check apex enforces apexOrgCoverageMin and apexClassCoverageMin. - Use Case: A deployment fails its test level because a new trigger has no coverage. Use this Skill to write a 200-record bulk trigger test with a TestDataFactory, assert governor-limit bounds, and rerun sf apex run test until the gate passes. ## Quick Start Ask the assistant to write a unit test with full coverage for a specific Apex class such as CaseEscalationService.cls.

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 an Apex unit test that meets the 75% code coverage requirement?

Create an @IsTest class with a @TestSetup method for shared records, wrap the code under test in Test.startTest() and Test.stopTest(), and assert outcomes with the Assert class. Every trigger needs some coverage, and conditional branches count only when both sides execute.

How do I test Apex HTTP callouts when tests do not support callouts?

Implement HttpCalloutMock and register it with Test.setMock before invoking the code under test. Use StaticResourceCalloutMock or MultiStaticResourceCalloutMock for static-resource responses, and WebServiceMock for WSDL2Apex SOAP stubs.

What is the difference between System.assertEquals and the Assert class in Apex?

Assert is the modern API with methods like areEqual, isTrue, isNull, and isInstanceOfType, taking (expected, actual, message) arguments. System.assertEquals still compiles but is legacy and lacks message discipline, so new tests should use Assert.

Why does my Apex test pass in sandbox but fail in production?

Tests using @IsTest(SeeAllData=true) or relying on org data and metadata execute different branches when records or permissions differ. Create test data inside the test, assign permission sets explicitly, and stage deployments through a Full Sandbox.

How do I test asynchronous Apex like Queueable or Batch jobs?

Enqueue the job inside Test.startTest() and Test.stopTest(); it runs synchronously at stopTest, so assert results afterward. Batch tests allow at most 5 submitted jobs and process only one execute chunk, and platform events need Test.getEventBus().deliver().

When should I use System.runAs in an Apex test?

Use System.runAs to enforce a user's sharing rules and CRUD/FLS permissions for positive and negative security tests, or to avoid mixed DML errors when writing setup and non-setup objects together. Each runAs call counts against the DML statement limit.