
Running Apex Tests
Scaffold Salesforce Apex test classes with TestSetup, positive/negative/bulk cases, and a 90%+ coverage target before deploy.
Install
npx skills add https://github.com/forcedotcom/sf-skills --skill running-apex-testsWhat is this skill?
- Structured @IsTest class with TestSetup and Test Data Factory insert pattern
- Sections for positive tests, negative scenarios, and bulk data cases
- Given/When/Then style comments inside each test method skeleton
- Documented coverage target: 90%+ on the class under test
- Placeholder tokens for class name, object, method, and date for fast customization
Adoption & trust: 734 installs on skills.sh; 513 GitHub stars; 3/3 security scanners passed (skills.sh audits).
Recommended Skills
Agent Browservercel-labs/open-agents
Tddmattpocock/skills
Use My Browserxixu-me/skills
Test Driven Developmentobra/superpowers
Verification Before Completionobra/superpowers
Webapp Testinganthropics/skills
Journey fit
Primary fit
Apex tests gate Salesforce deployments and regressions, which solo ISVs and admins handle in the ship phase before production releases. The skill is a runnable test-class template and patterns for @IsTest execution—not feature implementation or infra monitoring.
Common Questions / FAQ
Is Running Apex Tests safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Running Apex Tests
/** * @description Test class for {{ClassName}} * Tests core functionality with positive, negative, and bulk scenarios. * @created {{Date}} * @coverage Target: 90%+ */ @IsTest private class {{ClassName}}Test { // ═══════════════════════════════════════════════════════════════════════════ // TEST DATA SETUP // ═══════════════════════════════════════════════════════════════════════════ @TestSetup static void setupTestData() { // Create test data using Test Data Factory pattern // This data is available to all test methods and rolled back after each List<{{ObjectName}}> records = TestDataFactory.create{{ObjectName}}s(5); insert records; } // ═══════════════════════════════════════════════════════════════════════════ // POSITIVE TESTS // ═══════════════════════════════════════════════════════════════════════════ /** * @description Tests successful {{methodUnderTest}} with valid input */ @IsTest static void test{{MethodUnderTest}}_ValidInput_Success() { // ───────────────────────────────────────────────────────────────────── // GIVEN - Set up test conditions // ───────────────────────────────────────────────────────────────────── {{ObjectName}} testRecord = [SELECT Id, Name FROM {{ObjectName}} LIMIT 1]; // TODO: Add any additional setup needed // ───────────────────────────────────────────────────────────────────── // WHEN - Execute the method under test // ───────────────────────────────────────────────────────────────────── Test.startTest(); {{ReturnType}} result = {{ClassName}}.{{methodUnderTest}}(testRecord); Test.stopTest(); // ───────────────────────────────────────────────────────────────────── // THEN - Verify expected outcomes // ───────────────────────────────────────────────────────────────────── Assert.isNotNull(result, 'Result should not be null'); // TODO: Add specific assertions for expected values // Assert.areEqual(expectedValue, result, 'Result should match expected value'); } // ═══════════════════════════════════════════════════════════════════════════ // NEGATIVE TESTS // ═══════════════════════════════════════════════════════════════════════════ /** * @description Tests {{methodUnderTest}} throws exception with null input */ @IsTest static void test{{MethodUnderTest}}_NullInput_ThrowsException() { // ───────────────────────────────────────────────────────────────────── // GIVEN - Null input // ───────────────────────────────────────────────────────────────────── {{ObjectName}} nullRecord = null; // ───────────────────────────────────────────────────────────────────── // WHEN/THEN - Verify exception is thrown // ───────────────────────────────────────────────────────────────────── try { Test.startTest(); {{ClassName}}.{{methodUnderTest}}(nullRecord); Test.stopTest(); Assert.fail('Expected exception was not thrown'); } catch (IllegalArgumentException e) { Assert.isTrue( e.getMessage().containsIgnoreCase('null') || e.getMessage().containsIgnoreCase('required'), 'Error message should indicate null/required issue: ' + e.getMessage() ); } } /** * @description Tests {{methodUnderTest}} handles invalid data gracefully */ @IsTest static void test{{MethodUnderTest}}_InvalidData_ReturnsError() { // ───────────────────────────────────────────────────────────────────── // GIVEN - Invalid input data // ───────────────────────────────────────────────────────────────────── {{ObjectName}} invalidRecord = new {{ObjectName}}( // TODO: Set invalid field values that should