From salesforce-commerce
Guides Salesforce Commerce testing: B2C Node.js units (Mocha/Jest), sfcc-ci CI/CD, linting, sandboxes; B2B Apex classes (75%+ coverage), LWC Jest, sf CLI validation. For tests/CI/CD.
How this skill is triggered — by the user, by Claude, or both
Slash command
/salesforce-commerce:sf-testingThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
**Fetch live docs before writing tests or setting up CI/CD.**
Fetch live docs before writing tests or setting up CI/CD.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing.htm| Layer | B2C (SFCC) | B2B (Lightning) |
|---|---|---|
| Unit | Mocha/Jest for JS cartridge logic | Apex test classes (@IsTest) |
| Component | N/A | LWC Jest (@salesforce/sfdx-lwc-jest) |
| Integration | SCAPI/OCAPI against sandbox | sf CLI deploy validation |
| E2E | Full checkout flow on sandbox | Full storefront flow on scratch org |
| Linting | ESLint (SFCC config) | ESLint (LWC), Apex PMD |
| Coverage | nyc/istanbul (aim 80%+) | Salesforce enforced minimum 75% |
Unit Testing:
dw.* API stubs (dw.system, dw.catalog, dw.order) via proxyquire or jest.mockIntegration Testing:
Linting and Code Quality:
CI/CD Pipeline (sfcc-ci):
1. sfcc-ci code:deploy -> upload cartridge
2. sfcc-ci code:activate -> activate version
3. npm test -> run unit tests
4. sfcc-ci job:run -> integration tests
Sandbox Management:
| Environment | Purpose |
|---|---|
| Development | Developer-specific feature work |
| Staging | Pre-production validation |
| Production | Controlled release deployment |
Apex Test Classes:
@IsTest; minimum 75% coverage enforced by Salesforce@TestSetup for shared test data across methodsSystem.assert(), System.assertEquals(), System.assertNotEquals()Test Data Factory Pattern:
@TestSetup
static void setupTestData() {
// Fetch live docs for TestDataFactory patterns
// Create accounts, products, orders for tests
}
Mock Callouts:
HttpCalloutMock interface for external HTTP calloutsStaticResourceCalloutMock for static response dataTest.setMock()LWC Jest Testing:
@salesforce/sfdx-lwc-jest@wire decorated propertiesjest.mocksf CLI Deployment Validation:
# Dry-run validation with test execution
sf project deploy start --dry-run --test-level RunLocalTests
# Run specific test classes
sf apex run test --class-names MyTestClass --result-format human
Code Coverage Requirements:
| Threshold | Context |
|---|---|
| 75% minimum | Salesforce deployment requirement (org-wide) |
| 85%+ recommended | Critical business logic (payments, orders) |
| 100% target | Apex triggers (keep triggers thin, test all paths) |
| Per-class tracking | sf apex run test --code-coverage reports per class |
B2C Pipeline (GitHub Actions pattern):
| Step | Command |
|---|---|
| Deploy | sfcc-ci code:deploy cartridge.zip -i $SANDBOX |
| Activate | sfcc-ci code:activate --version $VERSION |
| Test | npm test |
B2B Pipeline (Salesforce CLI pattern):
| Step | Command |
|---|---|
| Deploy | sf project deploy start --target-org staging |
| Test | sf apex run test --test-level RunLocalTests --code-coverage |
| Report | sf apex get test --test-run-id $ID |
// Pattern: B2C controller unit test
// Fetch live docs for proxyquire and dw.* mock patterns
// proxyquire('./Controller', {'dw/catalog/ProductMgr': mock})
// assert result matches expected
// Pattern: B2B Apex test with assertions
// Fetch live docs for @IsTest and System.assertEquals
// Test.startTest(); call method; Test.stopTest();
// System.assertEquals(expected, actual, 'message');
dw.* APIs; never rely on live Salesforce APIs in unit testsSystem.runAs() for user context and permission testingFetch the Apex testing guide, LWC Jest documentation, and sfcc-ci CI/CD reference for exact framework versions and configuration before implementing.
npx claudepluginhub orcaqubits/agentic-commerce-skills-plugins --plugin salesforce-commerceSets up Salesforce Commerce dev environment with sfcc-ci CLI for B2C, sf CLI for B2B, Business Manager access, sandbox management, dw.json/.sfdx config, and SFRA/PWA Kit/Lightning project structures. Use for new projects.
Generates and validates Apex test classes with TestDataFactory patterns, bulk testing (251+ records), mocking, and assertion best practices. Useful when creating new tests, improving coverage, or debugging failing tests.
Executes Apex tests against a connected sandbox org via sf apex run test, parses coverage delta and failure stack traces, and suggests fixes. Use when you need to run test classes, check coverage, or diagnose test failures.