使用方法
- 复制安装命令,在自己的智能体环境安装前先检查源码包。
- 从原始文档核对所需工具、凭据和支持的宿主。
- 说明输入材料与期望交付物,并对照来源检查输出。
npx skills add https://github.com/phatnt95/salesforce-apex-agent --skill apex-testing开始前需了解
- 安装不包含模型订阅、API 额度或访问文件的权限。
- 仓库星数和安装量反映活跃情况,不等于独立质量或安全测试。
按源仓库内容呈现,保留标题、案例、代码、表格、链接以及原文引用的演示图片。
Apex Testing
Testing strategy
Test behavior and business outcomes, not just coverage percentage.
Every non-trivial feature should consider:
- Happy path.
- Boundary/edge cases.
- Invalid input.
- Bulk input.
- No-data behavior.
- Permission/security behavior when applicable.
- Exception/error behavior.
- Async behavior when applicable.
- Callout success/failure when applicable.
Test data
- Prefer isolated test data created by the test or a reusable factory.
- Avoid depending on existing org data unless the platform requires it and the dependency is explicit.
- Make test records minimal but realistic.
- Do not hard-code production IDs.
Assertions
- Assert meaningful field values, record counts, status transitions, errors, and side effects.
- Avoid tests that only assert no exception was thrown.
- Use
Test.startTest()/Test.stopTest()to isolate governor limits and flush supported async work. - For bulk logic, test a meaningful multi-record collection rather than only a single record.
Callouts
Use HttpCalloutMock or the appropriate test abstraction. Assert both request/response behavior and resulting Salesforce state.
Async
For Queueable, Batchable, Scheduled, and future work, verify the observable outcome after Test.stopTest() and cover failure paths where practical.
Quality gate
Before declaring a test complete, ask:
- Would this fail if the business rule broke?
- Does it protect against regression?
- Does it exercise bulk behavior?
- Does it verify important negative/security cases?
- Is it independent of org-specific production data?



