Agent Skillsforcedotcom/sf-skills › platform-apex-test-run

platform-apex-test-run

GitHub

用于执行Apex测试、分析代码覆盖率及修复失败测试。支持测试范围发现、结果诊断与结构化修复循环,涵盖断言、批量处理及异步测试最佳实践,排除生产代码编写和LWC测试场景。

skills/platform-apex-test-run/SKILL.md forcedotcom/sf-skills

Trigger Scenarios

用户需要运行Apex测试 检查代码覆盖率 修复失败的测试用例 处理 *Test.cls 或 *_Test.cls 文件

Install

npx skills add forcedotcom/sf-skills --skill platform-apex-test-run -g -y
More Options

Use without installing

npx skills use forcedotcom/sf-skills@platform-apex-test-run

指定 Agent (Claude Code)

npx skills add forcedotcom/sf-skills --skill platform-apex-test-run -a claude-code -g -y

安装 repo 全部 skill

npx skills add forcedotcom/sf-skills --all -g -y

预览 repo 内 skill

npx skills add forcedotcom/sf-skills --list

SKILL.md

Frontmatter
{
    "name": "platform-apex-test-run",
    "metadata": {
        "version": "1.1"
    },
    "description": "Apex test execution, coverage analysis, and test-fix loops with 120-point scoring. Use when the user needs to run Apex tests, check code coverage, fix failing tests, or work with *Test.cls \/ *_Test.cls files. TRIGGER when: 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)."
}

platform-apex-test-run: Salesforce Test Execution & Coverage Analysis

Use this skill when the user needs Apex test execution and failure analysis: running tests, checking coverage, interpreting failures, improving coverage, and managing a disciplined test-fix loop for Salesforce code.

When This Skill Owns the Task

Use platform-apex-test-run when the work involves:

  • sf apex run test workflows
  • Apex unit-test failures
  • code coverage analysis
  • identifying uncovered lines and missing test scenarios
  • structured test-fix loops for Apex code

Delegate elsewhere when the user is:

  • writing or refactoring production Apex → platform-apex-generate skill
  • testing Agentforce agents → agentforce-test skill
  • testing LWC with Jest → experience-lwc-generate

Required Context to Gather First

Ask for or infer:

  • target org alias
  • desired test scope: single class, specific methods, suite, or local tests
  • coverage threshold expectation
  • whether the user wants diagnosis only or a test-fix loop
  • whether related test data factories already exist

Recommended Workflow

1. Discover test scope

Identify:

  • existing test classes
  • target production classes
  • test data factories / setup helpers

2. Run the smallest useful test set first

Start narrow when debugging a failure; widen only after the fix is stable.

3. Analyze results

Focus on:

  • failing methods
  • exception types and stack traces
  • uncovered lines / weak coverage areas
  • whether failures indicate bad test data, brittle assertions, or broken production logic

4. Run a disciplined fix loop

When the issue is code or test quality:

  • delegate code fixes to platform-apex-generate skill when needed
  • add or improve tests
  • rerun focused tests before broader regression

5. Improve coverage intentionally

Cover:

  • positive path
  • negative / exception path
  • bulk path (251+ records where appropriate)
  • callout or async path when relevant

High-Signal Rules

Rule Rationale
Default to SeeAllData=false Ensures test isolation; prevents reliance on org-specific data
Every test must assert meaningful outcomes Tests with no assertions prove nothing and give false confidence
Test bulk behavior with 251+ records Triggers process in batches of 200; 251 records crosses the boundary
Use factories / @TestSetup when they improve clarity Consistent data creation in one place; rolled back between test methods
Pair Test.startTest() with Test.stopTest() for async Ensures async operations (queueable, future) complete before assertions
Do not hide flaky org dependencies inside tests Prevents intermittent failures tied to org state

Gotchas

Issue Resolution
Test passes locally but fails in CI org Check for SeeAllData=true or undeclared dependencies on org-specific records
Coverage drops unexpectedly after refactor Run focused class-level tests first, then widen to RunLocalTests to confirm
"Uncommitted work pending" error in callout test DML and HTTP callouts cannot be mixed in the same test context without Test.startTest() wrapping
Mock not taking effect in test Ensure Test.setMock() is called before the code that makes the callout
@TestSetup data missing in test method @TestSetup data is committed per test method — re-query it; do not store in static variables

Output Format

When finishing, report in this order:

  1. What tests were run
  2. Pass/fail summary
  3. Coverage result
  4. Root-cause findings
  5. Fix or next-run recommendation

Suggested shape:

Test run: <scope>
Org: <alias>
Result: <passed / partial / failed>
Coverage: <percent / key classes>
Issues: <highest-signal failures>
Next step: <fix class, add test, rerun scope, or widen regression>

Cross-Skill Integration

Need Delegate to Reason
Fix production code or author test classes platform-apex-generate skill Code generation and repair
Create bulk / edge-case test data platform-data-manage Realistic test datasets
Deploy updated tests to org platform-metadata-deploy Deployment workflows
Inspect detailed runtime logs platform-apex-logs-debug Deeper failure analysis

Reference File Index

File When to read
references/cli-commands.md All sf apex run test command flags, output formats, async execution, and coverage commands
references/test-patterns.md Test class templates — basic, bulk (251+), mock callout, and data factory patterns
references/testing-best-practices.md Core testing principles — AAA pattern, naming conventions, bulk, negative, and mock strategies
references/test-fix-loop.md Agentic test-fix loop implementation and failure analysis decision tree
references/mocking-patterns.md HttpCalloutMock, DML mocking, StubProvider, and selector mocking patterns
references/performance-optimization.md Techniques to reduce test execution time — DML mocking, SOQL mocking, loop optimizations
assets/basic-test.cls Template: standard test class with @TestSetup, positive / negative / bulk / edge-case methods
assets/bulk-test.cls Template: bulk test with 251+ records that crosses the 200-record trigger batch boundary
assets/mock-callout-test.cls Template: HTTP callout mock using HttpCalloutMock
assets/test-data-factory.cls Template: reusable TestDataFactory with create and insert helpers
assets/dml-mock.cls Template: IDML interface + DMLMock implementation for database-free unit tests
assets/stub-provider-example.cls Template: StubProvider-based dependency injection stub
scripts/parse-test-results.py Post-tool hook — parses sf apex run test JSON output and formats failures for the auto-fix loop

Score Guide

Score Meaning
108+ strong production-grade test confidence
96–107 good test suite with minor gaps
84–95 acceptable but strengthen coverage / assertions
< 84 below standard; revise before relying on it

Version History

  • 1.29.0 Current 2026-07-05 18:51

Same Skill Collection

skills/automation-flow-generate/SKILL.md
skills/commerce-b2b-open-code-components-integrate/SKILL.md
skills/commerce-b2b-store-create/SKILL.md
skills/data360-activate/SKILL.md
skills/data360-code-extension-generate/SKILL.md
skills/data360-prepare/SKILL.md
skills/data360-schema-get/SKILL.md
skills/design-systems-slds-apply/SKILL.md
skills/dx-org-permission-set-assign/SKILL.md
skills/dx-org-switch/SKILL.md
skills/experience-lwc-generate/SKILL.md
skills/experience-ui-bundle-features-generate/SKILL.md
skills/experience-ui-bundle-file-upload-generate/SKILL.md
skills/experience-ui-bundle-metadata-generate/SKILL.md
skills/experience-ui-bundle-site-generate/SKILL.md
skills/external-diagram-visual-generate/SKILL.md
skills/platform-apex-logs-debug/SKILL.md
skills/platform-custom-application-generate/SKILL.md
skills/platform-custom-tab-generate/SKILL.md
skills/platform-lightning-app-coordinate/SKILL.md
skills/platform-list-view-generate/SKILL.md
skills/platform-metadata-deploy/SKILL.md
skills/platform-permission-set-generate/SKILL.md
skills/platform-validation-rule-generate/SKILL.md
skills/agentforce-architecture-analyze/SKILL.md
skills/agentforce-d360-analyze/SKILL.md
skills/agentforce-generate/SKILL.md
skills/agentforce-observe/SKILL.md
skills/agentforce-test/SKILL.md
skills/commerce-b2b-open-code-components-replace/SKILL.md
skills/data360-connect/SKILL.md
skills/data360-harmonize/SKILL.md
skills/data360-orchestrate/SKILL.md
skills/data360-query/SKILL.md
skills/data360-segment/SKILL.md
skills/design-systems-slds-validate/SKILL.md
skills/design-systems-slds2-migrate/SKILL.md
skills/dx-app-analytics-query/SKILL.md
skills/dx-code-analyzer-configure/SKILL.md
skills/dx-code-analyzer-custom-rule-create/SKILL.md
skills/dx-code-analyzer-run/SKILL.md
skills/dx-devops-test-failures-analyze/SKILL.md
skills/dx-devops-test-pipeline-configure/SKILL.md
skills/dx-devops-test-suite-assignments-configure/SKILL.md
skills/dx-devops-test-suite-run/SKILL.md
skills/dx-org-manage/SKILL.md
skills/experience-cms-brand-apply/SKILL.md
skills/experience-content-media-search/SKILL.md
skills/experience-ui-bundle-agentforce-client-generate/SKILL.md
skills/experience-ui-bundle-app-coordinate/SKILL.md
skills/experience-ui-bundle-custom-app-generate/SKILL.md
skills/experience-ui-bundle-deploy/SKILL.md
skills/experience-ui-bundle-frontend-generate/SKILL.md
skills/experience-ui-bundle-salesforce-data-access/SKILL.md
skills/external-diagram-mermaid-generate/SKILL.md
skills/integration-connectivity-connected-app-configure/SKILL.md
skills/integration-connectivity-generate/SKILL.md
skills/integration-eventing-cdc-configure/SKILL.md
skills/integration-eventing-subscription-configure/SKILL.md
skills/mobile-apps-create/SKILL.md
skills/mobile-platform-native-capabilities-integrate/SKILL.md
skills/mobile-platform-offline-validate/SKILL.md
skills/omnistudio-callable-apex-generate/SKILL.md
skills/omnistudio-datamapper-generate/SKILL.md
skills/omnistudio-datapacks-deploy/SKILL.md
skills/omnistudio-dependencies-analyze/SKILL.md
skills/omnistudio-epc-catalog-generate/SKILL.md
skills/omnistudio-flexcard-generate/SKILL.md
skills/omnistudio-integration-procedure-generate/SKILL.md
skills/omnistudio-omniscript-generate/SKILL.md
skills/platform-agentexchange-partner-offers-configure/SKILL.md
skills/platform-agentsetup-categories-fetch/SKILL.md
skills/platform-apex-generate/SKILL.md
skills/platform-apex-test-generate/SKILL.md
skills/platform-custom-field-generate/SKILL.md
skills/platform-custom-lightning-type-generate/SKILL.md
skills/platform-custom-object-generate/SKILL.md
skills/platform-data-manage/SKILL.md
skills/platform-docs-get/SKILL.md
skills/platform-flexipage-generate/SKILL.md
skills/platform-metadata-api-context-get/SKILL.md
skills/platform-metadata-retrieve/SKILL.md
skills/platform-sharing-rules-generate/SKILL.md
skills/platform-soql-query/SKILL.md
skills/platform-tracing-agentforce-configure/SKILL.md
skills/platform-tracing-configure/SKILL.md
skills/platform-trust-archive-manage/SKILL.md
skills/platform-value-set-generate/SKILL.md

Metadata

Files
0
Version
1.29.0
Hash
734ed724
Indexed
2026-07-05 18:51

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-07-09 01:05
浙ICP备14020137号-1 $bản đồ khách truy cập$