assert
A 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.
assert(x)->equals(y) replaces the more verbose cl_abap_unit_assert=>assert_equals(act = ... exp = ...) call, once a test class inherits from the library's ZCL_ASSERTABLE_UNIT base class. The same fluent object works outside unit tests too, through a ZCL_ASSERTABLE class or an assert interface implemented directly in another class, and a resumable exception lets a caught assertion failure be fixed and resumed rather than always failing the caller.
Facts
Where it sits
Who is behind it
In the atlas: maintains 9@abapifymaintainerLars HvamContributes to this
In the atlas: maintains 13, contributes to 92, wrote 1@larshpPetr PlenkovContributes to this
In the atlas: contributes to 13@ThePlenkov2 contributors
What it declares
Every artifact
- Type
- Package
- Origin
- Independently maintained
As a package
- Where it runs
- Inside its host
- Distributed through
- does not say
Connections
BDD/TDD assertion library for ABAP Unit, styled after Chai.js
Testing application logic, with test doubles for its dependencies
Download
README
quoted from abapify/assert under MIT, readAssert library
In the beginning this project contained class ZCL_ASSERT. We had to rename it becase the class was already reserved in dotabap registry.
Following official documentation we're supposed to write unit tests using following template
cl_abap_unit_assert=>assert_equals( act = myclass=>text
exp = 'X' ).
The only function this library delivers - it allows us to use shorter construction like this:
assert( myclass=>text )->equals( 'X' ).
Usage in unit tests
To use this library you need to use ZCL_ASSERTABLE_UNIT class as a base class for your test class.
CLASS ltcl_main DEFINITION INHERITING FROM zcl_assertable_unit
FINAL FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.
...
endclass.
then later in your code you can just use something like:
assert( 1 )->not_initial( ).
assert( 1 )->eq( 1 ).
assert( 1 )->ne( 2 ).
assert( new ltcl_main( ) )->bound( ).
assert( not_bound )->not_bound( ).
assert( abap_true )->true( ).
assert( abap_false )->false( ).
Working with references
You might have a reference pointing to the value and you would like to compare not the reference but the value it refers to. Instead of dereferencing in your using test you can write something like:
assert( data_reference )->ref( )->equals( 'Some value' ).
Please notice that it expects that actual value is a data refence and will throw an error if it's not.
Local asserts
It might be helpful to use assert interface in a normal runtime, not only in unit tests.
data(assert) = new zcl_assertable( ).
assert->assert( 1 )->not_initial( ).
or if your class is inherited from ZCL_ASSERTABLE then simply like this
assert( 1 )->not_initial( ).
alternatively you can implement zif_assert interface right in your class:
class zcl_your_class definition.
public section.
interfaces zif_assertable.
private section.
aliases assert for zif_assertable~assert.
methods some_method.
endclass.
class zcl_your_class implementation.
method zif_assertable~assert.
result = new zcl_assertable( actual = actual ).
endmethod.
method some_method.
assert( some_value )->eq( another_value ).
endmethod.
endclass.
PLease notice in this case if
zif_assertableinterface will be extended ( with methods/parameters ) you will have to support this change too in your class.
Exception handling in local mode
One more feature which local asserts bring is a resumable exception. For example you can assert and catch assertion exception (which native asserts do not support BTW).
try.
assert( ref )->is_bound( ).
catch zcx_assertable.
" some exception handling
endtry.
Since ZCX_ASSERTABLE is a no-check exception you can bring it higher and do even more advanced logic
method main.
try.
do_something( ref ).
catch before unwind zcx_assertable.
" fix the problem here
ref = new #( ).
resume.
endtry.
endmethod.
method do_something.
assert( ref )->is_bound( ).
endmethod.History
Others providing
Compare all 21 on the Unit testing page →- 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
- 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
- @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
- abap_db_preparatorabap_db_preparatorA 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.independent, abapReplays stored database snapshots in ABAP unit tests
- 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:abapify-assert- JSON
- /artifacts/abapify-assert.json
- MCP
- Connecting an agent