kugamon/salesforce-core-skills

sf-test

Generates, reviews, and runs Salesforce Apex test classes with a 120-point test-quality scoring rubric using a Salesforce MCP server.

Vedi sorgente

Come usare

  1. Copia il comando e controlla il pacchetto prima di installarlo nel tuo ambiente agente.
  2. Controlla strumenti, credenziali e ambienti richiesti nel documento originale.
  3. Descrivi input e risultato desiderato; confronta l’output con le fonti.
npx skills add https://github.com/kugamon/salesforce-core-skills --skill sf-test

Prima di iniziare

  • L’installazione non include abbonamenti, quote API o accesso ai file.
  • Stelle e installazioni indicano attività, non un test indipendente di qualità o sicurezza.
Documento Skill originale

Contenuto dal repository con titoli, esempi, codice, tabelle, link e immagini preservati.

Salesforce Apex Test Generation, Review, and Execution

Expert Apex test engineer. Generate meaningful tests — not coverage padding — with proper isolation, bulk safety, permission awareness, and assertions that would actually catch regressions. Deploy and run via a Salesforce MCP server.

Dispatch

Parse $ARGUMENTS to determine which workflow to run:

First argument or intentWorkflow
generate, "write tests for X"Generate Tests
review, "score my tests", "are these good"Review Tests
run, "run the tests", "what's my coverage"Run Tests
No argumentAsk which workflow; if a class name is given, default to Generate

Execution modes

Detect the execution mode once per session — see references/execution-modes.md. In sfdx-repo mode, read classes from disk; otherwise fetch via MCP. Initialize the org connection first (org_init — your MCP server's session-init step; if none exists, verify with SELECT Id FROM Organization LIMIT 1).


Generate Tests

Phase 1: Understand the code under test

  1. Fetch the target class/trigger body (Tooling API query on ApexClass /

ApexTrigger, or read from disk in sfdx-repo mode).

  1. Map the surface: public/global methods, @AuraEnabled, @InvocableMethod,

@future, Queueable/Batchable/Schedulable interfaces, callouts (Http, HttpRequest, named credentials), DML and SOQL operations, custom exceptions, and branching logic.

  1. Fetch dependencies that affect test data: required fields, validation

rules, and record types on the objects touched (sobject_describe / metadata read). Tests fail in real orgs because of validation rules the generator never saw — check them up front.

Phase 2: Design the test plan

Build a test matrix BEFORE writing code. Cover every row that applies:

DimensionWhat to include
Positive pathEach public method's happy path with realistic data
Negative pathInvalid inputs, empty lists, nulls, exception branches asserted via try/catch or Assert.fail() sentinel
Bulk200-record operations through the same code path
PermissionsSystem.runAs() with a minimally-privileged user where the code enforces CRUD/FLS or sharing
AsyncTest.startTest()/stopTest() to flush futures/queueables; Test.getEventBus().deliver() for platform events
CalloutsHttpCalloutMock / WebServiceMock implementations per external call
BoundaryGovernor-relevant sizes, date boundaries, recursion guards

Present the matrix to the user when scope is ambiguous; otherwise proceed.

Phase 3: Generate the test class

Rules that make tests worth having:

  • One test class per production class, named <ClassName>Test.

@IsTest annotation, private, API version matching the class under test.

  • `@TestSetup` for shared data; a TestDataFactory pattern

(see references/test-patterns.md) when 3+ test classes need the same objects. A copyable starting file lives at ../../shared/templates/TestDataFactory.cls — copy it and extend per object; the reference doc explains the pattern. Never SeeAllData=true unless testing something that genuinely requires org data (document why in a comment).

  • Modern `Assert` class (Assert.areEqual, Assert.isTrue,

Assert.fail) with a message on every assertion explaining what broke. Every test method asserts something meaningful — method-ran-without-error is not a test.

  • `Test.startTest()/stopTest()` around the action under test only — not

around data setup — so governor limits reset where it matters and async work flushes.

  • Bulk test proves bulkification: build 200 records, run the path, assert

on ALL results (not just the first record), and keep it under limits.

  • runAs tests prove security: create a user with a minimal profile or

permission set, System.runAs() the restricted path, assert the enforcement (exception or stripped fields) actually happens.

  • No dependencies between test methods. Each method stands alone.

Phase 4: Deploy

Deploy the test class via the MCP metadata tool (metadata_create / metadata_update equivalents). On compile errors, fix and redeploy — common causes are missing required fields on test data (re-check Phase 1 findings), API-version mismatches, and SOQL WHERE clauses on non-filterable fields (long text areas can't be filtered in SOQL — query without the filter and filter in memory instead). When you get to running the tests, remember runTestsAsynchronous is POST-only — a GET returns 405.

Phase 5: Run and report

Run the new tests (see Run Tests below), then report: pass/fail per method, coverage delta on the class under test, and the test-quality score (see Scoring). Flag any class still below 75% coverage — the deployment minimum — and below 85%, the recommended bar for AppExchange submissions.


Review Tests

Score one or more existing test classes against the 120-point rubric.

  1. Fetch the test class body plus the production classes it covers.
  2. Evaluate each rubric category (below); cite line-level evidence for every

deduction — "no message on Assert at line 42", not "assertions could be better".

  1. Output a scored report:

| Test class | Score | % | Verdict | Top issues | | ---------- | ----- | -- | ------- | ---------- | | FooTest | 96/120 | 80% | ✅ Pass | No runAs coverage; 2 assert-free methods |

Threshold: 80/120 (67%) passes; below that, list the remediation plan in priority order (missing assertions first — they're the cheapest fix with the highest regression-catching value).

Test-Quality Scoring (120 points)

CategoryPointsWhat earns them
Assertion quality25Every method asserts outcomes with messages; negative paths assert exceptions; no assert-free methods
Data setup & isolation20@TestSetup / factory pattern; no SeeAllData; required fields handled; no inter-test dependencies
Bulk & governor safety20200-record path exercised; assertions over the full set; startTest/stopTest placed correctly
Coverage breadth20All public methods + branches; boundary cases; not just the happy path
Permission & sharing15runAs with restricted user where code enforces security; both allow and deny asserted
Async & callout handling15Mocks for every callout; async flushed and results asserted; platform events delivered
Structure & naming5<ClassName>Test naming; one concern per method; readable arrange-act-assert

Scoring notes: a test class with high line coverage but weak assertions caps at 60/120 — coverage without assertions is the most expensive false comfort in Salesforce development, and the rubric is deliberately built to punish it.


Run Tests

MCP-first execution via the Tooling API (works in every execution mode; in cli mode sf apex run test is the alternate path):

  1. Queue the run — Tooling API runTestsAsynchronous with the test class

IDs, or insert an ApexTestQueueItem per class via Tooling DML.

  1. Poll status — `SELECT Id, Status, ApexClassId FROM ApexTestQueueItem

WHERE ParentJobId = '<jobId>' until all rows are Completed, Failed, or Aborted`.

  1. Fetch results — `SELECT Outcome, MethodName, Message, StackTrace,

ApexClass.Name, RunTime FROM ApexTestResult WHERE AsyncApexJobId = '<jobId>'`.

  1. Fetch coverage — `SELECT ApexClassOrTrigger.Name, NumLinesCovered,

NumLinesUncovered FROM ApexCodeCoverageAggregate WHERE ApexClassOrTrigger.Name IN (...)` (Tooling API).

  1. Report — pass/fail table, failure messages with stack traces, coverage

per class, org-wide coverage if requested. For failures, offer to hand off to sf-debug (log analysis) or sf-apex (fix the production code).

Never run tests you just generated against a production org without telling the user — test runs consume async capacity and coverage recalculation can be slow in large orgs. Prefer sandboxes when the user has one connected.


Cross-skill handoffs

  • Production code fixes or refactors → sf-apex (150-point rubric)
  • Test failures needing log analysis → sf-debug
  • Coverage strategy for an AppExchange submission → sf-security

(review-readiness checklist includes the 75% bar and test quality)

References

FileRead when
references/test-patterns.mdWriting factories, mocks, async/event tests, runAs patterns
references/execution-modes.mdStart of session — detect mode

Correlati per attività

dallo stesso repository

Altri Skills

Tutti gli Skills
kugamon
Community

sf-audit

Run a comprehensive Salesforce org audit producing 18 documents from a single scan. Inventories and scores Apex classes, triggers, Flows, Process Builders, Workflow Rules, LWC components, custom objects/fields, validation rules, formula fields, approval processes, escalation/assignment/auto-response rules, Profiles, and Permission Sets. Detects unused custom fields and objects (no data and/or no references in code, flows, layouts, or reports). Also covers Reports & Dashboards, integrations, test

installazioni
1
GitHub Stars
2
Aggiornato
9 set
kugamon
Community

sf-diagram

Creates Salesforce architecture diagrams using Mermaid with ASCII fallback. Use when visualizing OAuth flows, data models (ERDs), integration sequences, system landscapes, role hierarchies, or Agentforce agent architectures. Do NOT use for inventorying or scoring org metadata (use sf-audit), retrieving object and field definitions (use sf-metadata), or auditing who has access to what (use sf-permissions) — this skill draws diagrams from data those skills supply. Usage: /sf-diagram [oauth|erd|int

installazioni
1
GitHub Stars
2
Aggiornato
9 set
kugamon
Community

sf-orgdiff

Compares two connected Salesforce orgs through their MCP connectors — inventory-first metadata diffing across Apex, Flows, objects/fields, validation rules, permission sets, layouts, labels, endpoints, and installed packages — producing a drift report with severity flags and a reconciliation plan. Strictly read-only on both orgs. Use when the user asks "what drifted", "compare orgs", "sandbox vs production", "did the release deploy everything", "compare against baseline", pre/post-release verifi

installazioni
1
GitHub Stars
2
Aggiornato
9 set