PackagePackagetypeA library you install and call yourself.See every one →What this type is →independently maintainedindependently maintainedoriginPublished by one person or a small company outside SAP. Says nothing about quality; the readings say that.See every one →

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

Last pushLicenceMIT

Where it sits

Lives in
Provides
Unit testingABAPUnit testingcapabilityTesting application logic without a running business process — and the test doubles that make dependencies on the database and on framework services tractable.

Who is behind it

Bunyanuch SaengnetBunyanuch SaengnetPersonMaintains this
In the atlas: maintains 1, contributes to 1
@bunysae
maintainerJohannes GerbershagenPersonContributes to this
In the atlas: maintains 1, contributes to 7
@germanysources
Lars HvamPersonContributes to this
In the atlas: maintains 13, contributes to 92, wrote 1
@larshp
2 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

Connections1

README

quoted from bunysae/abap_db_preparator under MIT, read
bunysae/abap_db_preparator/README.mdOn GitHub

ABAP 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. program zexport_gui 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 tableFake database tableSQL where restriction
SCARRZCARR_FAKEcarrid in ('TG', 'AA')
SPFLIZSPFLI_FAKEFOR 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 tableFake database tableSQL where restriction
SFLIGHTZCARR_SFLIGHTfldate = '20210420' AND EXISTS ( SELECT * FROM spfli WHERE carrid = sflightcarrid AND connid = sflightconnid AND airpto = 'BKK' )
SPFLIZCARR_SPFLIFOR 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).

Blog entry on SAP community network Repository mirror

MIT, read
Unit testing
  1. abap2UI5 headless frontendDrives abap2UI5 app classes from ABAP Unit testsfrom ABAP
  2. @abap2ui5/mcp-serverMCP server for the abap2UI5 check, deploy and run loopfrom ABAP
  3. assertFluent assertion helper for ABAP Unit testsfrom ABAP
  4. @abaplint/transpilerTranspiles ABAP to JavaScript to run on Node.jsfrom ABAP
  5. Modernization Agents for SAP on AWSAWS agents for ABAP, PI/PO and BW modernisation workfrom ABAP
  6. cacamber-BDD-for-ABAPBDD framework turning Given/When/Then into ABAP Unit stepsfrom ABAP
  7. abap-utesthelpHelper classes for ABAP Unit tests and test doublesfrom ABAP
  8. regression_testSnapshot testing library for ABAP, from debugger or unit testfrom ABAP
  9. abapCovUploads ABAP Unit code coverage to codecov.iofrom ABAP
  10. ABAP remote filesystemVS Code extension editing ABAP systems over ADT as a filesystemfrom ABAP
  11. open-steamgateLocal ABAP server serving /IWBEP/ OData v2 without an SAP systemfrom ABAP
  12. express-icf-shimShim running an ABAP ICF handler behind an Express 4.x serverfrom ABAP
  13. open-abap-coreCore ABAP artifacts for code transpiled by @abaplint/transpilerfrom ABAP
  14. mockup_loaderLoader of Excel-prepared ABAP unit test data, with stub generationfrom ABAP
  15. mockAA free mocking framework for ABAP, published under the Apache License 2.0.from ABAP
  16. Vise_for_ABAPA characterisation-test helper: `ZCL_VISE=>GRIP` records a field's value once and fails a later run if it has changed.from ABAP
  17. abap-senchaBDD/TDD assertion library for ABAP Unit, styled after Chai.jsfrom ABAP
  18. abap-test-containerGitHub-hosted test data container for ABAP Cloudfrom ABAP
  19. abap-unit-runnerApplication job that runs and schedules ABAP Unit tests in the cloudfrom ABAP
  20. adash-servicesBackend exposing ABAP Unit runs and coverage over REST and ODatafrom ABAP

Details

Sources3
Added by handdiscovered herechecked
github.com/bunysae/abap_db_preparatortree, pushes, contributors, CIchecked
README.mdquoted, and what the entry declareschecked

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
discovered viaAdded by hand
first seen in the atlas
ecosystem and domainabap, developer-experience
abaplint
issues under its own abaplint configuration12
lines5,450
statements2,865
objects41
files62
analysed, master
abaplint version2.120.84
Contributors2

From the repository’s contributor list, .

History in the atlas1
  1. First seen.
For your agent
Ref
artifact:bunysae-abap-db-preparator
JSON
/artifacts/bunysae-abap-db-preparator.json
MCP
Connecting an agent