abap-sencha
A 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.
ABAP Unit's cl_abap_unit_assert methods read as a class name and a parameter list rather than a sentence, which chai.js-style assertions in other languages avoid. ABAP Sencha wraps the same ABAP Unit framework in three chainable styles, expect, should and assert, built from language-chain words like is, to and has, plus helpers such as given, when and then for describing a test in its own words. Beside the wrappers over cl_abap_unit_assert it adds chai-inspired checks such as length_of and one_of, and wrappers for cl_abap_testdouble mocking calls. A test class reaches all of it by inheriting from ZCL_ABAP_SENCHA, and it runs on top of cl_abap_unit_assert rather than replacing it, so the underlying framework's tooling and IDE support still apply. For tests described fully in natural language the maintainer points to Cacambercacamber-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, abap instead.
Facts
Where it sits
Who is behind it
In the atlas: maintains 3, contributes to 4@wozjacmaintainer
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
Fluent assertion helper for ABAP Unit tests
BDD framework turning Given/When/Then into ABAP Unit steps
Testing application logic, with test doubles for its dependencies
Download
README
quoted from wozjac/abap-sencha under MIT, readABAP Sencha 🍵
BDD / TDD assertion library for ABAP, inspired by Chai.js.
Chai.js allows you to work with 3 different flavors:

The goal of ABAP Sencha is to provide similar functionality in ABAP on top of the existing ABAP Unit framework to leverage its tooling and IDE support.
In a nutshell:
foo.should.equal('bar'); // chai.js
the( foo )->should->equal( 'bar' ). //ABAP Sencha
expect(foo).to.equal('bar'); // chai.js
expect( foo )->to->equal( 'bar' ). // ABAP Sencha
assert.equal(foo, 'bar'); // chai.js
assert->equal( actual = foo expected = 'bar' ) // ABAP Sencha
assert( foo )->equals( 'bar' ). // ABAP Sencha
Overview
ABAP Sencha tries to bring the style known from chai.js into ABAP. Obviously not everything, as it is not JavaScript. The main goals are:
- Enable the usage of all three styles:
should,expect, andassert. - Enable the usage of language chains with a fluent interface.
- Incorporate relevant functions from the chai.js API into ABAP if applicable.
- Introduce ABAP-specific methods to enhance the readability and convenience of tests.
Each of the style is introduced by a dedicated method, followed by
a language chain(s) ending with a check method like equals - which are
basically wrappers over cl_abap_unit_assert methods. Optionally, a negation
not can be used, as well as and method for chained, multiple checks.
State
The current version of the project is 1.0.0-beta.
But why?
I prefer chai.js and find tests written in the expect or should style to be more
readable compared to other forms. In the JavaScript world, chai is always my
preferred choice as it offers a good balance between readability and ease of use.
If you prefer tests to be fully described using natural language, you can check
out the BDD library for ABAP - Cacamber.
Styles
expect style
This style is introduced by the method expect.
expect( actual )->equals( 2 ).
expect( actual )->is->equal_to( 2 ).
expect( actual )->not( )->equal_to( 4 ).
expect( char_value )->has->length_of( 3 ).
expect( 1 )->to->be->one_of( some_values ).
expect( actual )->to->be->true( ).
expect( |def| )->contained_in( some_string_table ).
* and more
should style
In ABAP you can't use the original chai.js approach like someObject.should....
Additional "entry" methods are introduced - value/v/the/value_of after
which you can continue to use should style.
the( actual )should->equal( 2 ).
value( actual )->should->be->equal_to( 2 ).
value_of( actual )->should->not( )->equal_to( 4 ).
v( char_value )->should->have->length_of( 3 ).
value( 1 )->should->be->one_of( some_values ).
the( actual )->should->be->true( ).
the( |def| )->should->be->contained_in( some_string_table ).
* and more
assert style
CL_ABAP_UNIT_ASSERT=>... is the assert style already available in ABAP Unit,
but ABAP Sencha brings the assert style from chai.js:
assert( )->equal( actual = act expected = 1 ).
assert( actual )->equals_to( 8 ).
Additional functionality
Language chains properties
You can use language chainable properties to improve readability:
- is
- be
- been
- to
- does
- has
- have
- that
expect( actual )->does-not( )->equal( 4 ).
the( flag )->should->not( )->be->true( ).
Negation with not( )
Most of the check methods can be negated with not - in case the method
is not working with negation, an exception will be thrown.
expect( actual )->not( )->equal_to( 4 ).
the( actual )->should->not( )->be->true( ).
assert( foo )->is->not( )->equal( 'bar' ).
Method variations
Some methods have the same functionality exposed via different names,
such as equal, equals, equal_to, match_pattern, matches_pattern,
and so on. You can use whichever name feels more readable to you.
Multiple checks with and
You can chain related checks with and if you prefer:
expect( bonus-periodic )->is->true( )->and( bonus-amount )->equals( 70 ).
value( bonus-code )->should->equals( 'B' )->and( bonus-amount )->should->equals( 70 ).
assert( bonus-periodic )->is-true( )->and( bonus-amount )->equals( 70 ).
it, describe, when, then, given
ABAP Sencha introduces additional methods from the JavaScript world. These methods can be used to provide descriptions, which can be helpful due to the limited length of names in ABAP.
Note: maybe in future those methods provides additional functionality, there are some ideas.
given( 'the user uses the CET timezone' ).
timezone_mocked_for( cet ).
when( 'we request the header' ).
DATA(header) = cut->get_user_header( ).
then( 'it should be prepended by CET phrase' ).
the( header )->should->cover_pattern( '*CET user*' ).
They can be also used for making tests readable using a simple approach:
" redefined methods implemented
METHOD given.
super->given( ).
IF description CP '*request*report*configured*'.
configure_request_report( ).
" ...
ENDIF.
ENDMETHOD.
METHOD given.
super->given( ).
" see method daily_report_request
IF description CP '*request*report*configured*'.
configure_request_report( ).
" ...
ENDIF.
ENDMETHOD.
METHOD when.
super->when( ).
" see method daily_report_request
IF description CP '*report*requested*'.
cut->request_report( ).
ENDIF.
ENDMETHOD.
METHOD then.
super->then( ).
" see method daily_report_request
IF description CP '*module*receives*request*'.
verify_expectations( some_module_mock ).
ENDIF.
ENDMETHOD.
...
" test method
METHOD daily_report_request.
given( 'request report is configured' ).
when( 'report is requested' ).
then( 'module receives request' ).
ENDMETHOD.
You can refer to the class ZCL_ABAP_SENCHA_SAMPLES for the code samples.
chai-inspired methods
Aside from the ABAP Unit check methods, there are additional ones inspired by chai.js:
length_offor checking the length of internal tables or character-based valuesone_offor checking if a value is a member of an internal tablecontained_infor checking if a value is contained in a string, number or an internal table
Additional methods for test doubles
There are handy methods that wrap some functionalities related to test doubles:
mock,get_mock_for,get_test_double_for,create_test_double: wrappers forcl_abap_testdouble=>createconfigure_call: a wrapper forcl_abap_testdouble=>configure_callverify_expectations,verify: wrappers forcl_abap_testdouble=>verify_expectations
Usage
Inherit your test class from ZCL_ABAP_SENCHA to gain access to all the methods and chaining words.
Documentation
The class has documentation available via ABAP Docs. The exported, online version is available on https://wozjac.github.io/abap-sencha/.
Examples
Please check the unit tests in ZCL_ABAP_SENCHA for usage examples.
Additionally, you can check the sample class ZCL_ABAP_SENCHA_SAMPLES.
Covered CL_ABAP_UNIT_ASSERT methods
NOT - means the method might be negated, like not->cover_pattern("abba")
| CL_ABAP_UNIT_ASSERT | ABAP Sencha |
|---|---|
| ASSERT_BOUND, ASSERT_NOT_BOUND | BOUND (NOT), NOT_BOUND |
| ASSERT_CHAR_CP, ASSERT_CHAR_NP | (NOT) COVER_PATTERN |
| ASSERT_DIFFERS | NOT->EQUAL |
| ASSERT_EQUALS | EQUAL |
| ASSERT_EQUALS_FLOAT | use EQUAL + float tolerance parameter |
| ASSERT_FALSE | NOT->TRUE, FALSE |
| ASSERT_INITIAL, ASSERT_NOT_INITIAL | (NOT) INITITAL |
| ASSERT_NUMBER_BETWEEN | BETWEEN |
| ASSERT_RETURN_CODE, ASSERT_SUBRC | EXPECT_SUBRC, EXPECT_RETURN_CODE |
| ASSERT_TABLE_CONTAINS, ASSERT_TABLE_NOT_CONTAINS | (NOT) CONTAINED_IN |
| ASSERT_TEXT_MATCHES | MATCH_REGEX |
| ASSERT_THAT | SATISFY |
| ASSERT_TRUE | NOT->FALSE, TRUE |
| ASSUME_TRUE, ASSUME_FALSE | ASSUME->TRUE/FALSE |
| ASSUME_THAT | ASSUME->SATISFY |
| FAIL | FAIL |
| SKIP | SKIP |
Compatibility
The source code syntax is checked using abapLint v740sp08
Cloud version.
Technical design
ABAP Sencha functionality is delivered by one big class with internal redundancy. This is intended design, as its goal is to avoid additional calls in the ABAP Unit test framework stack traces as much as possible (which would be present if the functionality would be split into multiple, smaller pieces of code).
Similar projects
License
This plugin is licensed under the MIT license.
Author
Feel free to contact me:
Others providing
Compare all 21 on the Unit testing page →- 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
- 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
- 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
- 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-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
History in the atlas
- First seen.
For your agent
- Ref
artifact:wozjac-abap-sencha- JSON
- /artifacts/wozjac-abap-sencha.json
- MCP
- Connecting an agent