abap_db_preparator
A wrapper over ABAP's OpenSQL replacement service that exports chosen rows into a stored bundle and, in a unit test's setup, replays it as fake table content in two method calls.
Unit tests that fake database rows by hand, in a bespoke setup method, tend to break after a system copy or another database manipulation. This library exports the chosen rows into a bundle, stored either in an ECATT test data container or in a cluster (a binary MIME object in transaction smw0), and links each original table to a fake counterpart through class cl_osql_replace; a test's setup then replaces the content and activates the replacement in two method calls. It supports FOR ALL ENTRIES IN restrictions and joins expressed as subqueries when choosing the rows to export, and the code is backwards compatible to release 7.40 although the replacement service itself needs SAP NetWeaver 7.51 or 7.52. The import APIs can only be used in development systems where dangerous ABAP unit-test classes are enabled.
Facts
Where it sits
Who is behind it
In the atlas: maintains 1, contributes to 1@bunysaemaintainerJohannes GerbershagenContributes to this
In the atlas: maintains 1, contributes to 7@germanysourcesLars HvamContributes to this
In the atlas: maintains 13, contributes to 92, wrote 1@larshp2 contributors
Before choosing this
Signals
ActivityQuietNo published releases; repository quiet for 28 months
It publishes no releases, and its repository has been quiet for at least 24 full months. This may be normal for stable software; check whether its current state still fits your use.
What it declares
Every artifact
- Type
- Package
- Origin
- Independently maintained
As a package
- Where it runs
- Inside its host
- Distributed through
- abapGit
Connections
Testing application logic, with test doubles for its dependencies
Download
README
quoted from bunysae/abap_db_preparator under MIT, readABAP Database preparator
Database preparation for unit testing made simple. Store snapshots (bundles) of your database records for later use in unit tests.
No more breaking unit tests
The snapshots should avoid breaking unit tests after system copies and
other database manipulations. This is achieved by providing a wrapper
for the OpenSQL replacement service in class cl_osql_replace, that
makes huge setups unnecessary.
Good bye huge setups
Replace this huge setup method
METHOD setup.
DATA: airlines TYPE STANDARD TABLE OF zcarr_fake,
replaced_tables TYPE cl_osql_replace=>tt_replacement.
DELETE FROM airlines.
airlines = VALUE #(
( carrid = 'TG' carrname = 'Thai Airways' )
).
INSERT zcarr_fake FROM airlines.
replaced_tables = VALUE #(
( source = 'SCARR' target = 'ZCARR_FAKE' )
).
cl_osql_replace=>activate_replacement( EXPORTING
replacement_table = replaced_tables ).
ENDMETHOD.
by just two method calls:
METHOD setup.
DATA(db_preparator) = NEW zimport_bundle_from_tdc( tdc = 'ZAIRLINES'
tdc_version = 1 variant = 'ECATTDEFAULT' ).
db_preparator->replace_content_completly( ).
db_preparator->activate_osql_replacement( ).
ENDMETHOD.
How it works
Bundles are stored either in an ECATT test data container or in a cluster (binary MIME-object in transaction smw0).
Export step
In the first step we can choose the database records,
which should be exported into the bundle.
The OpenSQL replacement service needs a so called fake table with the same
structure as the original table. From this fake table the database records are
read or they are written back in this fake table. In the export step we link
original and fake table as shown in the picture below.
Figure 1 Export step for table scarr in program zexport_gui
In figure 1 the original table is named scarr, the fake table zcarr_fake.
Fake tables can be left empty, if the OpenSQL replacement service isn't installed.
FOR ALL ENTRIES IN
The SQL where restriction can be prefixed a FOR ALL ENTRIES IN, which acts
like the corresponding ABAP-statement. As internal table any original table from the bundle can be given. Internal table name should be 'X' && table_name. E.g.
| Database table | Fake database table | SQL where restriction |
|---|---|---|
| SCARR | ZCARR_FAKE | carrid in ('TG', 'AA') |
| SPFLI | ZSPFLI_FAKE | FOR ALL ENTRIES IN xzcarr_fake WHERE carrid = xzcarr_fake-carrid |
JOINS
Joins can be expressed with subqueries. Let's consider the following join:
SELECT * FROM sflight AS f INNER JOIN spfli AS p
ON p~carrid = f~carrid AND p~connid = f~connid
WHERE p~airpto = 'BKK' AND f~fldate = '20210420'.
The database records can be picked up in programm zexport_gui with subqueries:
| Database table | Fake database table | SQL where restriction |
|---|---|---|
| SFLIGHT | ZCARR_SFLIGHT | fldate = '20210420' AND EXISTS ( SELECT * FROM spfli WHERE carrid = sflight |
| SPFLI | ZCARR_SPFLI | FOR ALL ENTRIES IN xsflight WHERE carrid = xsflight-carrid AND connid = xsflight-connid |
Import step
In the ABAP unit-testclass the database records exported in previous step
can be imported in the fake tables or in the original tables,
if the corresponding fake table was left empty.
The API for the import step is located in class zimport_bundle_from_cluster
for clusters or in class zimport_bundle_from_tdc for
ECATT test data container.
For testing Rfc-Client- or Rfc-Serverprograms or programs,
which interact through the JSON Adapter for ABAP Function Modules
a API is located in function-group zimport_bundle.
A example can be found in the listing below.
CLASS test_airlines DEFINITION FOR TESTING DURATION SHORT
RISK LEVEL HARMLESS.
PRIVATE SECTION.
" activate replacement service
METHODS setup.
METHODS thai_should_be_found FOR TESTING.
ENDCLASS.
CLASS test_airlines IMPLEMENTATION.
METHOD setup.
DATA(db_preparator) = NEW zimport_bundle_from_tdc( tdc = 'ZAIRLINES'
tdc_version = 1 variant = 'ECATTDEFAULT' ).
db_preparator->replace_content_completly( ).
db_preparator->activate_osql_replacement( ).
ENDMETHOD.
METHOD thai_should_be_found.
DATA: exp_airlines TYPE STANDARD TABLE OF scarr.
exp_airlines = VALUE #( ( carrid = 'TG' carrname = 'Thai airways'
currcode = 'THB' url = 'https://thaiairways.com' ) ).
SELECT * FROM scarr INTO TABLE @DATA(act_airlines).
cl_abap_unit_assert=>assert_equals( exp = exp_airlines
act = act_airlines ).
ENDMETHOD.
ENDCLASS.
Authorization
The APIs in class zimport_bundle_from_cluster or
in class zimport_bundle_from_tdc can only be used in
development systems, where
dangerous ABAP unit-testclasses are enabled.
Whitelist-check
Content of fake tables listed in the whitelist can be completely
overriden. The whitelist is maintained in parameter
ZIMPORT_REPLACE_WHITELIST (transaction stvarv, table tvarvc).
Terms
- Bundle: a collection of database records, which are stored outside of the database tables.
- Cluster: a MIME-object in transaction
smw0, which contains the bundle - TDC: abbreviation for ECATT test data container
Cloning this repository
Cloning can be done with abapGit. The code is backwards compatible until release 7.40. The replacement services need higher releases (SAP NetWeaver 7.51 or 7.52).
Further links
Others providing
Compare all 21 on the Unit testing page →- abap2UI5 headless frontendabap2UI5 headless frontendPlays the frontend's side of the abap2UI5 request/response contract in ABAP, so an app class is driven and asserted on from a plain ABAP Unit test.community org, abapDrives abap2UI5 app classes from ABAP Unit tests
- @abap2ui5/mcp-server@abap2ui5/mcp-serverAn MCP server that puts the abap2UI5 development loop on the machine an agent runs on: check the view the ABAP builds, photograph it, deploy the class into a sandbox, boot the app headless and read the errors.community org, abapMCP server for the abap2UI5 check, deploy and run loop
- assertassertA fluent assertion helper for ABAP Unit tests that wraps cl_abap_unit_assert in chained calls such as assert(x)->equals(y), also usable outside tests through ZCL_ASSERTABLE.independent, abapFluent assertion helper for ABAP Unit tests
- @abaplint/transpiler@abaplint/transpilerTranspiles ABAP 7.02 syntax to ES6 JavaScript, so ABAP code and its unit tests run on Node.js in CI without an ABAP system, with optional SQLite, PostgreSQL, Snowflake or SAP HANA drivers.community org, abapTranspiles ABAP to JavaScript to run on Node.js
- Modernization Agents for SAP on AWSModernization Agents for SAP on AWSAWS's suite of agents for SAP modernisation work: custom ABAP converted for S/4HANA, PI/PO interfaces moved to Integration Suite, BW objects moved to SAP Datasphere, deployed into a customer's own AWS account and reached only after registration.partner, abapAWS agents for ABAP, PI/PO and BW modernisation work
- cacamber-BDD-for-ABAPcacamber-BDD-for-ABAPA BDD framework for ABAP that turns Gherkin-style Given/When/Then scenarios into ABAP Unit test steps, matching each step against a regular expression and calling the test class method it maps to.independent, abapBDD framework turning Given/When/Then into ABAP Unit steps
- abap-utesthelpabap-utesthelpTwo helper classes for ABAP Unit tests: one verifies a domain constant class against its domain's fixed values, the other creates test doubles without naming the interface.independent, abapHelper classes for ABAP Unit tests and test doubles
- regression_testregression_testA snapshot library for ABAP that records a value once and compares against it on every later run, from either the debugger or a unit test, storing snapshots in eCATT test data containers.independent, abapSnapshot testing library for ABAP, from debugger or unit test
- abapCovabapCovA report, ZABAPCOV, that uploads ABAP Unit test code coverage results to codecov.io, once the repository is installed through abapGit and codecov.io's certificates through STRUST.independent, abapUploads ABAP Unit code coverage to codecov.io
- ABAP remote filesystemABAP remote filesystemA Visual Studio Code extension that opens an ABAP system over ADT as an editable filesystem and exposes system tools to GitHub Copilot and external MCP clients.independent, abapVS Code extension editing ABAP systems over ADT as a filesystem
- open-steamgateopen-steamgateAn ABAP application server you clone and run on your own machine: transpiled ABAP serving classic /IWBEP/ OData v2 to Fiori over a local database, with no SAP system attached.independent, abapLocal ABAP server serving /IWBEP/ OData v2 without an SAP system
- express-icf-shimexpress-icf-shimA shim that runs an ABAP ICF handler written against if_http_extension behind an Express 4.x server, for ABAP transpiled to JavaScript and run on Node.js in testing and continuous integration.community org, abapShim running an ABAP ICF handler behind an Express 4.x server
- open-abap-coreopen-abap-coreReusable ABAP functionality for code transpiled by @abaplint/transpiler: the core ABAP artifacts that code runs against on Node.js.community org, abapCore ABAP artifacts for code transpiled by @abaplint/transpiler
- mockup_loadermockup_loaderA tool that loads ABAP unit test data prepared in Excel as TAB-delimited text into ABAP structures and tables, and generates interface stubs that return that mock data.independent, abapLoader of Excel-prepared ABAP unit test data, with stub generation
- mockAmockAA free mocking framework for ABAP, published under the Apache License 2.0.independent, abapA free mocking framework for ABAP, published under the Apache License 2.0.
- Vise_for_ABAPVise_for_ABAPA characterisation-test helper: ZCL_VISE=>GRIP records a field's value once and fails a later run if it has changed.independent, abapA characterisation-test helper: `ZCL_VISE=>GRIP` records a field's value once and fails a later run if it has changed.
- abap-senchaabap-senchaA BDD/TDD assertion library for ABAP Unit, styled after the JavaScript library Chai.js, that wraps cl_abap_unit_assert in chainable expect, should and assert styles.independent, abapBDD/TDD assertion library for ABAP Unit, styled after Chai.js
- abap-test-containerabap-test-containerA test data container for ABAP Cloud that loads unit test data in JSON, XML or raw formats from GitHub and maps it onto the target structure, filling the platform's missing native one.independent, abapGitHub-hosted test data container for ABAP Cloud
- abap-unit-runnerabap-unit-runnerAn application job that runs and schedules ABAP Unit tests in SAP's ABAP Environment through the SAP_COM_0735 API, where the on-premise test runner has no SAP GUI to run from.independent, abapApplication job that runs and schedules ABAP Unit tests in the cloud
- adash-servicesadash-servicesThe backend service behind ADASH Cli, exposing ABAP Unit test runs and coverage as REST and OData services for CI/CD pipelines, with a report scheduled to run tests per package.independent, abapBackend exposing ABAP Unit runs and coverage over REST and OData
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
abaplint
Contributors
History in the atlas
- First seen.
For your agent
- Ref
artifact:bunysae-abap-db-preparator- JSON
- /artifacts/bunysae-abap-db-preparator.json
- MCP
- Connecting an agent