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-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 Cacamber instead.

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

Jacek WozniczakJacek WozniczakPersonMaintains this
In the atlas: maintains 3, contributes to 4
@wozjac
maintainer

What it declares

Every artifact

Type
Package
Origin
Independently maintained

As a package

Where it runs
Inside its host
Distributed through
does not say

Connections3

README

quoted from wozjac/abap-sencha under MIT, read
wozjac/abap-sencha/README.mdOn GitHub

ABAP Sencha 🍵

BDD / TDD assertion library for ABAP, inspired by Chai.js.

Chai.js allows you to work with 3 different flavors:

chai js 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, and assert.
  • 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_of for checking the length of internal tables or character-based values
  • one_of for checking if a value is a member of an internal table
  • contained_in for 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 for cl_abap_testdouble=>create
  • configure_call: a wrapper for cl_abap_testdouble=>configure_call
  • verify_expectations, verify: wrappers for cl_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_ASSERTABAP Sencha
ASSERT_BOUND, ASSERT_NOT_BOUNDBOUND (NOT), NOT_BOUND
ASSERT_CHAR_CP, ASSERT_CHAR_NP(NOT) COVER_PATTERN
ASSERT_DIFFERSNOT->EQUAL
ASSERT_EQUALSEQUAL
ASSERT_EQUALS_FLOATuse EQUAL + float tolerance parameter
ASSERT_FALSENOT->TRUE, FALSE
ASSERT_INITIAL, ASSERT_NOT_INITIAL(NOT) INITITAL
ASSERT_NUMBER_BETWEENBETWEEN
ASSERT_RETURN_CODE, ASSERT_SUBRCEXPECT_SUBRC, EXPECT_RETURN_CODE
ASSERT_TABLE_CONTAINS, ASSERT_TABLE_NOT_CONTAINS(NOT) CONTAINED_IN
ASSERT_TEXT_MATCHESMATCH_REGEX
ASSERT_THATSATISFY
ASSERT_TRUENOT->FALSE, TRUE
ASSUME_TRUE, ASSUME_FALSEASSUME->TRUE/FALSE
ASSUME_THATASSUME->SATISFY
FAILFAIL
SKIPSKIP

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:

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

Details

Sources3
Added by handdiscovered herechecked
github.com/wozjac/abap-senchatree, 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 configuration0
lines3,614
statements2,427
objects4
files8
analysed, main
abaplint version2.120.84
History in the atlas1
  1. First seen.
For your agent
Ref
artifact:wozjac-abap-sencha
JSON
/artifacts/wozjac-abap-sencha.json
MCP
Connecting an agent