{"id":13698804,"url":"https://github.com/germanysources/regression_test","last_synced_at":"2025-03-18T22:31:17.794Z","repository":{"id":48440606,"uuid":"218513322","full_name":"germanysources/regression_test","owner":"germanysources","description":"Create snapshots in ABAP","archived":false,"fork":false,"pushed_at":"2024-06-24T08:19:04.000Z","size":362,"stargazers_count":11,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T12:45:06.242Z","etag":null,"topics":["abap","debugger-script","regression-tests"],"latest_commit_sha":null,"homepage":"","language":"ABAP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/germanysources.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-30T11:36:57.000Z","updated_at":"2024-12-30T02:01:04.000Z","dependencies_parsed_at":"2024-08-02T19:12:02.563Z","dependency_job_id":null,"html_url":"https://github.com/germanysources/regression_test","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/germanysources%2Fregression_test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/germanysources%2Fregression_test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/germanysources%2Fregression_test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/germanysources%2Fregression_test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/germanysources","download_url":"https://codeload.github.com/germanysources/regression_test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243954843,"owners_count":20374364,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abap","debugger-script","regression-tests"],"created_at":"2024-08-02T19:00:53.202Z","updated_at":"2025-03-18T22:31:17.491Z","avatar_url":"https://github.com/germanysources.png","language":"ABAP","funding_links":[],"categories":["Categories"],"sub_categories":["🧪 Testing"],"readme":"# Snapshots in ABAP #\n\n## Snapshots ##\nCreate snapshots either in the debugger or directly in your unit-tests.\nSnapshots are stored in ECATT test data containers (TDC).\n\n## Unit-Test ##\nSnapshots can be created with class ```zdbgl_snapshots_tdc```.\nThe following listing shows a sample unit-test using snapshots.\n```ABAP\nCLASS test_snapshot DEFINITION FOR TESTING\n  DURATION SHORT RISK LEVEL HARMLESS.\n\n  PRIVATE SECTION.\n\n    METHODS flight_test FOR TESTING\n      RAISING zcx_dbgl_snapshot.\n\nENDCLASS.\n\nCLASS test_snapshot IMPLEMENTATION.\n\n  METHOD flight_test.\n\n    DATA(snapshot_manager) = zdbgl_snapshots_tdc=\u003ecreate_default(\n      tdc_name = 'ZDBGL_SNAPSHOT_SAMPLE'\n    ).\n\n    DATA(carrier) = VALUE scarr_tab(\n      ( carrid = 'SAP' carrname = 'SAP Flights' )\n      ( carrid = 'IN' carrname = 'Internat. Airways' )\n    ).\n    DATA(flight) = VALUE sflight( carrid = 'SAP' connid = 700 fldate = '20201231' ).\n\n    snapshot_manager-\u003ecompare_or_record( name = 'CARRIER' actual = carrier ).\n    snapshot_manager-\u003ecompare_or_record( name = 'FLIGHT' actual = flight ).\n\n    \" can be omitted, when autosave = abap_true in factory method or constructor\n    snapshot_manager-\u003ecommit_changes( ).\n\n  ENDMETHOD.\n\nENDCLASS.\n```\nThe method ```snapshot_manager-\u003ecompare_or_record``` compares the given value with the recorded value or records the value. We need to give every value a unique name in the parameter ```name```.\nThe behavior (recording or comparing) is controlled with the SET/GET-parameter ```ZDBGL_SNAP_RECORD```.\nA value of 'X' means 'create/update the snapshot'.\n![Parameter ZDBGL_SNAP_RECORD](img/update_snap.png)\n\n### Comparison ###\nThe standard implementation uses the method ```cl_abap_unit_assert=\u003eassert_equals``` for comparison.\nOverride the method ```zdbgl_snapshots_tdc=\u003ecompare``` to specify another comparison method.\n\n### Restrictions ###\n* Structures must be defined in the ABAP dictionary. Structures defined outside of the ABAP dictionary can't be stored in test data containers.\n* Any kind of references (pointing to classes, interfaces or data objects) are not supported\n* Updating a snapshot closes the SAP-LUW with ```COMMIT WORK```. To avoid this, use debugger snapshots as described in the next section.\n\n## Debugger ##\n### Create snapshots ###\nAnother option to create snapshots is the debugger script ```zdbgl_script_store_in_tdc```.\nPrerequisite is an existing TDC.\n\n#### Prerequisite step: create ECATT test data container ####\nGo the transaction ```secatt``` and create a test data container. Add a parameter for every variable you want to record. The parameter should have the same name and type as the variable.\nLast but not least give the test data container API access as shown in the picture below.\n![Permit api access](img/tdc_permit_api_access.png)\n\n#### Before the modification ####\nSet an appropriate breakpoint and create the snapshot with the debugger-script ```zdbgl_script_store_in_tdc```.\n![Load script](img/load_script1.png)\nThis script asks you for the name, the version and the variant of the test data container as shown in the picture below.\n![Prompt tdc key](img/script_prompt_tdc.png)\n\n### Writing unit-tests ###\nWith the API in the class ```cl_apl_ecatt_tdc_api``` we can access the snapshot.\n\n### Example ###\nThe example can be found in the program ```zdbgl_demo_regression_test```.\n\nThe procedure ```to_verify``` is the procedure under test.\n```ABAP\nFORM to_verify.\n  FIELD-SYMBOLS: \u003cline\u003e TYPE sflight.\n\n  APPEND INITIAL LINE TO demo_itab ASSIGNING \u003cline\u003e.\n  \u003cline\u003e-carrid = 'LH'.\n  \u003cline\u003e-connid = '3444'.\n  \u003cline\u003e-price = 400.\n\nENDFORM.\n```\n\nIn the first step we create a snapshot before and after this procedure is executed.\n\nIn the second step we use the snapshot (test data container \"ZDBGL_SAMPLE\") to write unit-tests:\n```ABAP\nREPORT ZDBGL_DEMO_REGRESSION_TEST.\nDATA: demo_itab TYPE STANDARD TABLE OF sflight.\n\nSTART-OF-SELECTION.\n  FIELD-SYMBOLS: \u003cline\u003e TYPE sflight.\n\n  APPEND INITIAL LINE TO demo_itab ASSIGNING \u003cline\u003e.\n  \u003cline\u003e-carrid = 'LH'.\n  \u003cline\u003e-connid = '3445'.\n  \u003cline\u003e-price = 500.\n  BREAK-POINT. \"snapshot is created\n  PERFORM to_verify.\n  BREAK-POINT. \"snapshot is created\n\n\n\" subprogram should be verified.\n\" It changes the global variable demo_itab.\nFORM to_verify.\n  FIELD-SYMBOLS: \u003cline\u003e TYPE sflight.\n\n  APPEND INITIAL LINE TO demo_itab ASSIGNING \u003cline\u003e.\n  \u003cline\u003e-carrid = 'LH'.\n  \u003cline\u003e-connid = '3444'.\n  \u003cline\u003e-price = 400.\n\nENDFORM.\n\nCLASS regression_test DEFINITION FOR TESTING\n  DURATION SHORT RISK LEVEL HARMLESS.\n\n  PRIVATE SECTION.\n    DATA: tdc_accessor TYPE REF TO cl_apl_ecatt_tdc_api.\n\n    METHODS setup\n      RAISING cx_static_check.\n\n    METHODS verify_changed_itab FOR TESTING\n      RAISING cx_static_check.\n\nENDCLASS.\n\nCLASS regression_test IMPLEMENTATION.\n\n  METHOD setup.\n\n    tdc_accessor = cl_apl_ecatt_tdc_api=\u003eget_instance( EXPORTING\n      i_testdatacontainer = 'ZDBGL_SAMPLE' i_testdatacontainer_version = 1 ).\n\n  ENDMETHOD.\n\n  METHOD verify_changed_itab.\n    DATA: exp_demo_itab LIKE demo_itab.\n\n    \" given: use the snapshot before procedure under test was executed\n    tdc_accessor-\u003eget_value( EXPORTING i_param_name = 'DEMO_ITAB' i_variant_name = 'BEFORE'\n      CHANGING e_param_value = demo_itab ).\n\n    \" when: execute procedure under test\n    PERFORM to_verify.\n\n    \" then: use the snapshot after the procedure under test was executed\n    tdc_accessor-\u003eget_value( EXPORTING i_param_name = 'DEMO_ITAB' i_variant_name = 'AFTER'\n      CHANGING e_param_value = exp_demo_itab ).\n    cl_abap_unit_assert=\u003eassert_equals( exp = exp_demo_itab\n     act = demo_itab msg = 'Regression test not passed' ).\n\n  ENDMETHOD.\n\nENDCLASS.\n``` \n\n### Restrictions ###\nThese types are currently supported:\n* simple types (like characters, strings, integer)\n* flat structures (complex structures containing components with tables or structures are not supported)\n* tables with a flat structure or a simple type as the table line type\n\nThese types are not supported:\n* all form of references\n* complex structures\n* tables with complex structures as the table line type or with tables as the table line type\n\n### Legacy API ###\nThere is a legacy API to create snapshots in the debugger, which uses the database tables ```zdbgl_variables``` and ```zdbgl_locals``` as a temporary storage and which is bit more difficult to use. This API is documented in the [docs-folder](docs/README_legacy_v0.md).\n\n## Installation ##\nInstallation is done with [abapGit](https://github.com/larshp/abapgit). ABAP 7.40 or higher is needed.\nAll ABAP-objects have the prefix ```zdbgl```.\n\n## Logs ##\nExceptions are logged in the checkpoint-groups \"zdbgl_store_globals\" and \"zdbgl_store_locals\" (see transaction ```saab```).\nLogging is only active, if the checkpoint-groups is activated.\n\n## Dependencies ##\n- [ABAP-Logger](https://github.com/ABAP-Logger/ABAP-Logger) is used for display interactive messages\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgermanysources%2Fregression_test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgermanysources%2Fregression_test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgermanysources%2Fregression_test/lists"}