apex-test-class

Generates scalable, ready-to-use Aspen test classes with TestDataFactory patterns and mocking support.

803|289|Updated Nov 7, 2025
One-click install
npx skills add https://github.com/forcedotcom/afv-library --skill apex-test-class
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: apex-test-class
Source: https://github.com/forcedotcom/afv-library/tree/main/skills/testing-automation/apex-test-class
Command: npx skills add https://github.com/forcedotcom/afv-library --skill apex-test-class

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Apex test class scaffolding and patterns provide a standardized approach to writing thorough unit tests, enabling teams to generate bulk test data, isolate tests from org data, and validate behavior across triggers, services, controllers, batches, and integrations.

Core Features & Use Cases

  • Bulk test generation: use TestDataFactory patterns to create 200+ records for realistic governor-limit testing.
  • Data isolation and setup: leverage @TestSetup and TestDataFactory to keep tests deterministic.
  • Robust assertions & coverage: enforce meaningful assertions and test negative paths.
  • Mocking and async support: integrate HttpCalloutMock/Test.setMock and Test.startTest/Test.stopTest for callouts and asynchronous code.
  • Use Case: apply this skill when adding new tests, refactoring, or improving test patterns for triggers, services, controllers, batch jobs, queueables, and integrations.

Quick Start

Create a new Apex test class using the TestDataFactory patterns to bulk-generate 200+ records, then run tests to verify coverage and assertions.

Frequently Asked Questions about apex-test-class

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

FAQPage Schema
How do I write Apex test classes for bulk data and governor limits?

Apex test classes for bulk data use TestDataFactory patterns to generate 200+ records, ensuring realistic governor-limit testing. This approach isolates tests from org data and validates trigger and service behavior under heavy load.

How do I mock HTTP callouts in Apex test classes?

Mocking HTTP callouts in Apex test classes integrates HttpCalloutMock with Test.setMock to isolate external integrations. This pattern ensures deterministic test execution without relying on live external services.

What is the best way to isolate Apex unit tests from org data?

Isolating Apex unit tests from org data requires leveraging @TestSetup and TestDataFactory to keep tests deterministic. This ensures consistent coverage by creating fresh, controlled data sets for every test run.

Does Apex testing support asynchronous batch jobs and queueables?

Apex testing supports asynchronous batch jobs and queueables using Test.startTest and Test.stopTest. These methods ensure async processes execute synchronously within the test context, enabling accurate assertions.

Can I use a test data factory for Apex controllers and services?

A test data factory applies to Apex controllers, services, triggers, and batch jobs by generating standardized test records. This enables consistent coverage and robust assertions across various component types.