forcedotcom/sf-skills / plugins/builder/salesforce-development/skills/platform-apex-test-run
platform-apex-test-run
VerifiedApex test execution, coverage analysis, and test-fix loops with 120-point scoring. Use when the user runs Apex tests, checks code coverage, fixes failing tests, or touches *Test.cls / *_Test.cls files. DO NOT TRIGGER when writing Apex production code (use platform-apex-generate), Agentforce agent testing (use agentforce-test), or Jest/LWC tests (use experience-lwc-generate).
| File | Kind | Size |
|---|---|---|
| README.md | markdown | 3.0 KB |
| SKILL.md | skill md | 7.3 KB |
| assets/basic-test.cls | other | 12.7 KB |
| assets/bulk-test.cls | other | 11.3 KB |
| assets/dml-mock.cls | other | 12.6 KB |
| assets/mock-callout-test.cls | other | 13.6 KB |
| assets/stub-provider-example.cls | other | 12.2 KB |
| assets/test-data-factory.cls | other | 14.3 KB |
| references/cli-commands.md | markdown | 5.7 KB |
| references/mocking-patterns.md | markdown | 13.2 KB |
| references/performance-optimization.md | markdown | 7.5 KB |
| references/test-fix-loop.md | markdown | 2.0 KB |
| references/test-patterns.md | markdown | 4.2 KB |
| references/testing-best-practices.md | markdown | 15.6 KB |
| scripts/parse-test-results.py | script | 12.8 KB |
assets/basic-test.cls
View on GitHub/**
* @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 fail validation
);
// ─────────────────────────────────────────────────────────────────────
// WHEN - Execute with invalid data
// ─────────────────────────────────────────────────────────────────────
Test.startTest();
// TODO: Call method and capture result/exception
Test.stopTest();
// ─────────────────────────────────────────────────────────────────────
// THEN - Verify appropriate error handling
// ─────────────────────────────────────────────────────────────────────
// TODO: Assert error message or state
}
// ═══════════════════════════════════════════════════════════════════════════
// BULK TESTS (251+ records)
// ═══════════════════════════════════════════════════════════════════════════
/**
* @description Tests {{methodUnderTest}} handles bulk operations (251 records)
* 251 records crosses the 200-record trigger batch boundary
*/
@IsTest
static void test{{MethodUnderTest}}_BulkOperation_Success() {
// ─────────────────────────────────────────────────────────────────────
// GIVEN - 251 records (crosses 200-record batch boundary)
// ─────────────────────────────────────────────────────────────────────
List<{{ObjectName}}> bulkRecords = TestDataFactory.create{{ObjectName}}s(251);
// ─────────────────────────────────────────────────────────────────────
// WHEN - Process bulk records
// ─────────────────────────────────────────────────────────────────────
Test.startTest();
insert bulkRecords; // Triggers fire in batches of 200, then 51
Test.stopTest();
// ─────────────────────────────────────────────────────────────────────
// THEN - Verify all records processed without governor limit issues
// ─────────────────────────────────────────────────────────────────────
Integer recordCount = [SELECT COUNT() FROM {{ObjectName}}];
Assert.isTrue(recordCount >= 251, 'All 251 records should be processed');
// Verify governor limits not approached
Assert.isTrue(Limits.getQueries() < 90,
'SOQL queries should stay well under limit: ' + Limits.getQueries() + '/100');
Assert.isTrue(Limits.getDmlStatements() < 140,
'DML statements should stay under limit: ' + Limits.getDmlStatements() + '/150');
}
// ═══════════════════════════════════════════════════════════════════════════
// EDGE CASE TESTS
// ═══════════════════════════════════════════════────────────────────────────
/**
* @description Tests {{methodUnderTest}} with empty list input
*/
@IsTest
static void test{{MethodUnderTest}}_EmptyList_NoError() {
// ─────────────────────────────────────────────────────────────────────
// GIVEN - Empty list
// ─────────────────────────────────────────────────────────────────────
List<{{ObjectName}}> emptyList = new List<{{ObjectName}}>();
// ─────────────────────────────────────────────────────────────────────
// WHEN - Process empty list
// ─────────────────────────────────────────────────────────────────────
Test.startTest();
// TODO: Call method with empty list
Test.stopTest();
// ─────────────────────────────────────────────────────────────────────
// THEN - Should handle gracefully (no exception)
// ─────────────────────────────────────────────────────────────────────
// TODO: Assert appropriate handling
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |