Skip to content

forcedotcom/sf-skills / plugins/builder/salesforce-development/skills/platform-apex-test-generate

platform-apex-test-generate

Verified

Use to generate and validate Apex test classes with TestDataFactory patterns, bulk testing (251+ records), mocking, assertions, and disciplined test-fix loops. Use when creating Apex test classes (for triggers, services, controllers, batch jobs, queueables, and callouts), improving coverage, debugging or fixing failing Apex tests, or running test/coverage analysis. Triggers on *Test.cls files, sf apex run test, coverage reports. Do NOT trigger for production Apex (use platform-apex-generate) or Jest/LWC tests.

assets/test-class-template.cls

View on GitHub
/**
 * Test class for {ClassUnderTest}.
 * Tests bulk operations (251+ records), positive/negative paths,
 * and exception handling.
 */
@isTest
private class {ClassUnderTest}Test {

    @TestSetup
    static void setupTestData() {
        List<Account> accounts = TestDataFactory.createAccounts(251, true);
    }

    // ─── Positive Tests ───────────────────────────────────────────────────

    @isTest
    static void shouldPerformExpectedBehavior_WhenValidInput() {
        // Given
        List<Account> accounts = [SELECT Id, Name FROM Account];

        // When
        Test.startTest();
        // {ClassUnderTest}.methodUnderTest(params);
        Test.stopTest();

        // Then
        // Assert.areEqual(expected, actual, 'Descriptive failure message');
    }

    @isTest
    static void shouldHandleBulkRecords_WhenProcessing251() {
        // Given
        List<Account> accounts = [SELECT Id FROM Account];
        Assert.areEqual(251, accounts.size(), 'Should have 251 test records');

        // When
        Test.startTest();
        // {ClassUnderTest}.bulkMethod(accounts);
        Test.stopTest();

        // Then
        // List<Account> results = [SELECT Id, Status__c FROM Account];
        // for (Account acc : results) {
        //     Assert.areEqual('Processed', acc.Status__c, 'All records should be processed');
        // }
    }

    // ─── Negative Tests ───────────────────────────────────────────────────

    @isTest
    static void shouldThrowException_WhenNullInput() {
        Test.startTest();
        try {
            // {ClassUnderTest}.methodUnderTest(null);
            Assert.fail('Expected exception for null input');
        } catch (MyCustomException e) {
            Assert.isTrue(e.getMessage().contains('cannot be null'),
                'Exception message should mention null input');
        }
        Test.stopTest();
    }

    @isTest
    static void shouldReturnEmpty_WhenEmptyInput() {
        Test.startTest();
        // List<SObject> results = {ClassUnderTest}.methodUnderTest(new List<Id>());
        Test.stopTest();

        // Assert.isTrue(results.isEmpty(), 'Should return empty list for empty input');
    }

    // ─── Edge Case Tests ──────────────────────────────────────────────────

    @isTest
    static void shouldHandleMixedRecords_WhenSomeQualify() {
        // Given
        List<Account> accounts = [SELECT Id, Status__c FROM Account];
        Integer half = accounts.size() / 2;
        // for (Integer i = 0; i < half; i++) {
        //     accounts[i].Status__c = 'Qualifying';
        // }
        // update accounts;

        // When
        Test.startTest();
        // {ClassUnderTest}.conditionalMethod(accounts);
        Test.stopTest();

        // Then
        // List<Account> qualifying = [SELECT Id FROM Account WHERE Processed__c = true];
        // Assert.areEqual(half, qualifying.size(), 'Only qualifying records should be processed');
    }
}
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
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: 198kUpdated Claude CodeCodexVerifiedInstall