/sap-gen-code:sap-gen-abap-unit <OBJECT_NAME | path-to.abap> [--type class|fm|program|auto] [--target-coverage <n>] [--max-rounds 3] [--doubles auto|osql|none] [--deploy ask|yes|no] [--risk-level harmless|dangerous|critical] [--no-gui]from sap-gen-code
Generates ABAP Unit tests for existing SAP objects (classes, function modules, reports) and closes the loop: deploy, activate, run with coverage, fix until green. Pairs with /sap-run-abap-unit.
Ships in sap-gen-code. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You generate an ABAP Unit test class for an existing object, then close the loop: pre-check → deploy → activate → run-with-coverage → read failures → fix → repeat until tests pass and coverage meets the target (or you report honestly what is not testable without a refactor). The generation is your reasoning; the deploy / activate / run / coverage half reuses skills that are already live-tested.
This skill observes shared/rules/skill_operating_rules.md. Rule 2 (no
unsolicited deployment) applies: generation is read-only, but the deploy/run
loop writes a test artifact to SAP — it is gated behind --deploy (default ask).
Task: $ARGUMENTS
Vocabulary. This is the
genhalf of the ABAP-unit pair:sap-gen-abap-unit(you) generates →/sap-run-abap-unitruns. Same "abap-unit" token on purpose.
| File / token | Path | Purpose |
|---|---|---|
sap_settings_lib.ps1 | <SAP_DEV_CORE_SHARED_DIR>\scripts\sap_settings_lib.ps1 | settings merge |
sap_connection_lib.ps1 | <SAP_DEV_CORE_SHARED_DIR>\scripts\sap_connection_lib.ps1 | Get-SapWorkDir, Get-SapCurrentSessionPath |
sap_object_resolver.ps1 | <SAP_DEV_CORE_SHARED_DIR>\scripts\sap_object_resolver.ps1 | type + TADIR identity |
sap_rfc_read_source.ps1 | <SAP_DEV_CORE_SHARED_DIR>\scripts\sap_rfc_read_source.ps1 | Read-SapAbapSource (program/include/FM) |
sap_explain_parse.ps1 | <SAP_DEV_CORE_SHARED_DIR>\..\skills\sap-explain-object\references\sap_explain_parse.ps1 | source → map.json (units / externals / db reads+writes) — drives the seam analysis |
| SE24 download VBS | <SAP_DEV_CORE_SHARED_DIR>\..\skills\sap-se24\references\sap_se24_check_and_download.vbs | class source (GUI) |
sap_attach_lib.vbs (%%ATTACH_LIB_VBS%%) | <SAP_DEV_CORE_SHARED_DIR>\scripts\sap_attach_lib.vbs | AttachSapSession for the download VBS |
abap_code_quality_rules.md (§15) | <SAP_DEV_CORE_SHARED_DIR>\rules\abap_code_quality_rules.md | the ABAP Unit emission rules (FOR TESTING DURATION SHORT RISK LEVEL HARMLESS, cl_abap_unit_assert=>assert_*) |
customer_brief.md | {custom_url}\customer_brief_<LANG>.md → {custom_url}\customer_brief.md → built-in _<LANG> variant → built-in template (<LANG>: userConfig.template_language → userConfig.sap_language → EN) | MODE_MIN_COVERAGE, MODE_OOP, release, risk level |
sap_log_helper.ps1 | <SAP_DEV_CORE_SHARED_DIR>\scripts\sap_log_helper.ps1 | structured logging |
Skills this one orchestrates (skills-first, per CLAUDE.md Rule 6 — invoke via
the Skill tool, never re-implement): /sap-check-abap, /sap-transport-request,
/sap-se24 (--test-source), /sap-se38, /sap-activate-object,
/sap-run-abap-unit.
<SAP_DEV_CORE_SHARED_DIR> = plugins/sap-dev-core/shared — 3 levels up from
<SKILL_DIR>, then into sap-dev-core\shared.
powershell -NoProfile -ExecutionPolicy Bypass -Command ". '<SAP_DEV_CORE_SHARED_DIR>\scripts\sap_settings_lib.ps1'; . '<SAP_DEV_CORE_SHARED_DIR>\scripts\sap_connection_lib.ps1'; Write-Output ('WORK_DIR=' + (Get-SapWorkDir)); Write-Output ('CUSTOM_URL=' + (Get-SapSettingValue 'custom_url' ((Get-SapWorkDir) + '\custom'))); Write-Output ('RUN_TEMP=' + (Get-SapRunTemp))"
Settings reads/writes follow <SAP_DEV_CORE_SHARED_DIR>/rules/settings_lookup.md.
Set {WORK_TEMP} = {work_dir}\temp, {OUT} = {WORK_TEMP}\aunit_gen\{OBJECT},
and {RUN_TEMP} = the RUN_TEMP= value printed above (Get-SapRunTemp mints +
creates a fresh per-run dir {work_dir}\temp\run_<id> — holds the log state
file; mint once here and reuse the same value in Step 0.5 and Final).
cmd /c if not exist "{OUT}" mkdir "{OUT}"
powershell -ExecutionPolicy Bypass -File "<SAP_DEV_CORE_SHARED_DIR>\scripts\sap_log_helper.ps1" -Action start -StateFile "{RUN_TEMP}\sap_gen_abap_unit_run.json" -Skill sap-gen-abap-unit -ParamsJson "{\"target\":\"<OBJECT>\"}"
| Arg | Default | Notes |
|---|---|---|
| positional | — | Object name (uppercase) OR a .abap file path (FILE mode = generate from local source, no acquisition). |
--type | auto | class / fm / program. |
--target-coverage <n> | brief MODE_MIN_COVERAGE / 0 | Coverage % to drive the fix loop toward. |
--max-rounds <n> | 3 | Cap on generate→run→fix iterations. |
--doubles <m> | auto | auto = pick per dependency (Step 4); osql = force OSQL DB doubles; none = no doubles (pure-function tests only). |
--deploy <m> | ask | ask confirms before each write; yes runs the loop unattended; no generates + pre-checks only (no SAP write). |
--risk-level <l> | brief / harmless | Caps the emitted RISK LEVEL. The client's SAUNIT_CLIENT_SETUP is the real gate. |
--no-gui | false | RFC-only acquisition; class bodies degrade to signature; deploy loop unavailable (needs GUI). |
If the positional is missing, ask and stop.
Same acquisition the comprehension skills use:
sap_object_resolver.ps1 (32-bit, creds
fall back to the pinned profile) → {TYPE}, {PGMID}, TADIR object code. Then:
Read-SapAbapSource -Name '{OBJECT}' -Type '{TYPE}' -OutDir '{OUT}' -WithIncludes (RFC).%%CLASS_NAME%% %%OUTPUT_FILE%% %%SESSION_PATH%% %%ATTACH_LIB_VBS%%, set $env:SAPDEV_SESSION_PATH, run 32-bit cscript) — as /sap-explain-object does.{OUT}\source.txt; infer type + name from the top-level statement.Source lands at {OUT}\source.txt.
powershell -NoProfile -ExecutionPolicy Bypass -File "<SAP_DEV_CORE_SHARED_DIR>\..\skills\sap-explain-object\references\sap_explain_parse.ps1" -SourceDir "{OUT}" -OutFile "{OUT}\map.json"
map.json gives the units (methods/FORMs to cover), externals (CALL
FUNCTION / CALL METHOD edges = candidate seams), and db_reads / db_writes (the
SELECTs that need OSQL doubles). Read the customer brief (MODE_MIN_COVERAGE,
MODE_OOP, ABAP release → modern syntax, default risk level) and
abap_code_quality_rules.md §15 (the canonical test-class shape).
For each unit under test, classify every dependency from map.json and pick a
strategy. Be honest — legacy code with hard-wired statics is not magically
unit-testable.
| Dependency (from map.json) | Strategy | Emitted scaffold |
|---|---|---|
SELECT on a table (db_reads/db_writes) | OSQL test double (auto/osql) | cl_osql_test_environment=>create( … ) in class_setup, …->insert_test_data( lt_rows ) per test, teardown …->destroy( ). Code under test runs unchanged, reads the doubles. |
| Dependency injected via constructor / setter (interface ref) | CL_ABAP_TESTDOUBLE | cl_abap_testdouble=>create( '<IF>' ), …=>configure_call( )->returning( ), inject into the CUT. |
Static CALL FUNCTION / CALL METHOD with side effects, no seam | Flag SEAM_NEEDED | No double possible without a wrapper. Emit a " TODO seam: comment + a testability.md entry recommending the minimal injection refactor. Cover the pure parts only. |
| Pure unit (inputs → outputs, no I/O) | Direct | arrange / act / cl_abap_unit_assert=>assert_equals( … ) with boundary + equivalence cases. |
Write {OUT}\testability.md — per unit: covered / partial / not-testable + reason.
This is the honesty contract; never imply coverage you can't deliver.
{TYPE} | Container | Deploy via | Run via |
|---|---|---|---|
class | CCAU Local Test Classes include — CLASS ltcl_…_test DEFINITION FOR TESTING … + IMPLEMENTATION only (NOT the global class) → {OUT}\{OBJECT}_CCAU.abap | /sap-se24 {OBJECT} --test-source={OUT}\{OBJECT}_CCAU.abap | /sap-run-abap-unit {OBJECT} --type=CLASS --with-coverage |
fm | a standalone test program Z<NS>_<FM>_UT whose local test class CALL FUNCTION '{OBJECT}' and asserts on outputs | /sap-se38 | /sap-run-abap-unit Z<NS>_<FM>_UT --type=PROGRAM --with-coverage |
program | a test program Z<NS>_<RPT>_UT (or Z<PROGRAM_ID>_TEST for /sap-gen-abap output) | /sap-se38 | /sap-run-abap-unit <container> --type=PROGRAM --with-coverage |
Report honesty. A report's logic in
FORMs cannot be called from a separate program. For a report, test only what is reachable: Z* FMs/classes it calls, or aSUBMIT … AND RETURNcharacterization test against known input (integration- level — mark it as such). If the logic is monolithicFORMs with no seam, say so and recommend extracting a testable class; do not fabricate coverage.
Emit the container source to the path in the table above, following
abap_code_quality_rules.md §15 and the brief (release-correct syntax — heed the
[sap-gen-abap inline-type pitfalls] the generator already knows: no
STANDARD TABLE OF dbtab in METHODS sigs on 7.52, named types not anonymous
@DATA() in method params, no inline DATA(...) in CALL FUNCTION IMPORTING).
Shape: CLASS ltcl_… DEFINITION FOR TESTING DURATION SHORT RISK LEVEL {RISK},
setup / teardown (+ class_setup/class_teardown for the OSQL environment),
one FOR TESTING method per behavior with arrange/act/assert. Keep method names
descriptive (test_<unit>_<case>).
Run /sap-check-abap {OUT}\<test-source> to catch naming/type/syntax issues
before touching SAP. Fix anything it flags, then proceed. (This is the cheap
gate; it has no false-green for the patterns it knows.)
Skip entirely if --deploy no (stop after Step 6 with the generated source +
testability report). Otherwise, with --deploy ask confirm before the first
write; with --deploy yes run unattended. Resolve a TR once via
/sap-transport-request.
Loop, round = 1 … --max-rounds:
/sap-se24 --test-source=… for a class, /sap-se38
for a program)./sap-activate-object (test includes/programs deploy inactive)./sap-run-abap-unit <container> --type=<T> --with-coverage --min-coverage=<target>.AUNIT_VERDICT: PASS and coverage ≥ target → done, exit the loop.ALERT: lines) or coverage < target, and round < max-rounds →
feed the failing class::method — message lines and the uncovered units back
into your generation, regenerate the affected tests, and repeat.SKIPPED:NO_TESTS → generation produced nothing runnable; stop and report
(Step 4 likely flagged the object untestable).round = max-rounds without green: stop and report the best state honestly
(passing tests + remaining failures + achieved coverage). Never loop unbounded.Respect skill_operating_rules Rule 2 at every write: under ask, surface the
exact object + TR and wait for confirmation.
Summarize: object + type, container deployed, tests passing/total, coverage
achieved vs target, rounds used, and — prominently — the testability report
(units covered / partial / needing a seam refactor). Point the user at
{OUT}\testability.md and the generated source. If --deploy no, say the tests
were generated + pre-checked but not deployed, and give the one-line deploy command.
powershell -ExecutionPolicy Bypass -File "<SAP_DEV_CORE_SHARED_DIR>\scripts\sap_log_helper.ps1" -Action end -StateFile "{RUN_TEMP}\sap_gen_abap_unit_run.json" -Status SUCCESS -ExitCode 0
| Outcome | Status / ExitCode / ErrorClass |
|---|---|
| Tests pass + coverage met | -Status SUCCESS -ExitCode 0 |
Generated, not deployed (--deploy no) | -Status SUCCESS -ExitCode 0 |
| Loop ended with failures / below coverage | -Status FAILED -ExitCode 1 -ErrorClass AUNIT_GEN_NOT_GREEN -ErrorMsg "failed=F cov=C%" |
| Object untestable without refactor | -Status SKIPPED -ExitCode 0 -ErrorClass AUNIT_GEN_NO_SEAM |
| Source could not be acquired | -Status FAILED -ExitCode 2 -ErrorClass AUNIT_GEN_SOURCE_UNAVAILABLE |
--max-rounds bounds it.FORMs cap what
unit testing can reach — the skill flags this rather than faking coverage.aunit_coverage_gate (warn vs block).fm and program containers), the coverage
run scopes to that test program — whose only code is test code — so the production
logic under test (e.g. the FM in its own function group) is not counted and
coverage reads 0.00 / NA even though the tests pass. This is expected, not a
failure: report tests-pass and coverage separately, and tell the user that FM
coverage requires measuring the function group. The class (CCAU) container
does capture coverage, because the test class sits inside the class under test.--deploy and /sap-transport-request; nothing
reaches SAP without a TR and (under ask) confirmation.existing object ──► [ sap-gen-abap-unit ] ──► /sap-se24 --test-source | /sap-se38
(generate + seam) (deploy)
└──► /sap-activate-object ──► /sap-run-abap-unit --with-coverage ──► (fix loop)
Complements /sap-gen-abap (which emits Z<PROGRAM_ID>_TEST alongside new code):
this skill brings the same test discipline to brownfield objects that shipped
with no tests. A regression safety net here is the precondition the sap-migrate
remediation flow wants before it changes anything.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
abap-unit, test-generation, sap-development, coverage, seam-analysis
12 skills in this plugin
/sap-docs-checkValidates an extracted design spec before ABAP code generation, across two
dimensions: `ddic` checks DDIC objects (domains / data elements / tables) —
naming, data-type validity, domain/DTEL/table cross-references, currency-ref
completeness, the primitive-as-data-element trap; `process` checks the
process-logic text for unclear/ambiguous steps, missing info, and logic /
type / cross-reference inconsistencies. Both optionally verify references
against the live system over RFC when a SAP logon is given. Runs BOTH by default
(whichever inputs exist); --dimension ddic|process forces one. Writes a
TAB-separated result file per dimension for Excel review. Replaces the former
/sap-docs-check-ddic and /sap-docs-check-process.
Input: work folder path; optional SAP Logon description enables the RFC checks.
/sap-docs-convertApplies customer-specific normalisation rules to the extracted spec files
in a work folder. Reads `spec_conversion_rules.tsv` (default at
sap-dev-core/shared/tables/, override at {custom_url}/spec_conversion_rules.tsv)
and rewrites the affected `_*.txt` files in place.
Three rule categories:
* field_rename — legacy field name → canonical name
* type_rename — legacy DDIC type token → canonical token
* flag_mapping — legacy flag value → one or more KEY=VALUE pairs
Plus optional schema migration (legacy customer YAML/TSV layout → Customer
Brief layout).
Input: work folder containing the extracted `_*.txt` files (output of /sap-docs-extract).
Output: same files rewritten in place; a `.pre-convert/` snapshot is taken first.
This skill is OPTIONAL — projects already authoring specs in Customer Brief
format can skip it entirely.
/sap-docs-estimateTurn the spec pipeline's structural signals into a transparent, falsifiable effort estimate
— no gut feel. `score` reads a spec work folder's `_*.txt` DDIC/process/interface counts and
`/sap-docs-check` ambiguity rows, applies published weights, and maps the complexity class to
a WIDE effort band with named drivers and an assumptions register. `--batch` rolls up a
portfolio of specs; `--ledger` bands a `/sap-cc-triage` migration wave by (tier x object
type). `record-actuals` appends real hours to an append-only ledger so every estimate becomes
measurable; `calibrate` (v1.5) tightens the multipliers once enough pairs accrue. Pure-local,
read-only, no SAP access in v1 (a `--live-delta` brownfield-credit RFC mode is v2). Every
report is labelled UNCALIBRATED so a wide band can never masquerade as a commitment.
/sap-docs-extractReads a SAP design document (Excel .xlsx, Word .docx, PDF) — or an existing work
folder / a _raw.txt file — and extracts structured information into separate text
files by type: program summary, domains, data elements, tables, error messages,
text elements, and process logic. From a document it creates a fresh work folder,
dumps {doc_name}_raw.txt, then structures; existing {doc_name}_*.txt files are
silently overwritten. Optionally chain /sap-docs-convert afterwards for
customer-specific normalisation, then /sap-docs-check and /sap-gen-abap. Legacy
binary .doc is not supported (save as .docx first); an unsupported format aborts
with "ERROR: Unsupported file format."
/sap-docs-layoutEdits the structural layout of a SAP design spec template (.xlsx) by writing
to the workbook's `(Meta) Layout` sheet. Lets customers customize sheet
names, column orders, and output mappings without editing Markdown rules or
skill code. The meta sheet becomes the per-workbook source of truth that
`/sap-docs-extract` reads on its next run.
Operations:
inspect Print the current layout in human-readable form.
bootstrap Copy a `(Meta) Layout` sheet from the canonical
`spec_template.xlsx` into a workbook that doesn't have one.
add-column Add a column to a section. Updates xlsx + meta in one step.
rename-sheet Rename a sheet and update meta so the parser still finds it.
validate Reconcile the meta sheet against actual workbook structure.
Input: workbook path + operation + op-specific args.
Output: in-place modifications to the .xlsx file. A timestamped backup is
written next to the original before any write operation.
/sap-gen-abapGenerates ABAP source code from a process text file ({doc_name}_process.txt)
produced by sap-docs-extract. Supports generating:
- Dialog/Module Pool programs
- ABAP Reports (帳票/バッチ)
- Function Modules / RFC
Uses variable naming conventions from sap-dev-core/shared/tables/abap_naming_rules.tsv (or custom override from {custom_url}).
Prerequisites: Run /sap-docs-convert and /sap-docs-extract first.
npx claudepluginhub sapdev-ai/sap-dev --plugin sap-gen-code