ABAP CDS Test Double Framework
CDS Test Double Framework enables you to test the logic expressed in CDS entities in an automated way.
Challenges with Conventional ABAP Solutions
The logic in a CDS entity is executed in the underlying database, which is independent of the ABAP runtime, which means it is not possible to use conventional ABAP solutions for inserting dependencies. The depended-on components (DOC) of the CDS need to be doubled in the database. It needs to be ensured that the database engine calls or executes these Test Doubles instead of the dependent component when the CDS is tested.
To test the logic in CDS entity under test (CUT), test data must be inserted in the double. This data is returned by the Test Doubles when the CUT is executed. CUT must not be modified by the test framework to enable unit or hierarchical testing.
CDS Test Double Framework
Use CDS Test Double Framework to address these challenges. It enables unit or hierarchical testing of CDS views by automatically creating “updatable” Test Doubles for each dependent component in the same database schema. The framework double that is created is a stub which has the same structure as the original dependent component.
CDS Test Double Framework
The figure below shows an ABAP Unit test for a CDS view. The dependent CDS Views have been replaced with test double tables. By imitating the behavior of the original CDS views, test double tables provide a CDS view under test with the data created with a test class wizard.
Unit Test with CDS Test Double Framework
The figure below shows the hierarchical testing of two CDS views. To test the views, a dependent CDS View and two dependent tables are replaced by the appropriate test double tables.
Hierarchical Test with CDS Test Double Framework
Supported Test Scenarios
CDS Test Double framework supports creation of test doubles for the following dependent components:
- ABAP Dictionary tables
- ABAP Dictionary views
- CDS views
- CDS views with parameters
- CDS view entities
- CDS view entities with parameters
- Projection views
- External views
- Table functions
- Special CDS functions (CURRENCY_CONVERSION and UNIT_CONVERSION)
- Shared tables (For all share types like R, W, T, and S)
- Session variables
CDS test double framework supports the following entities as code under test:
- CDS views
- CDS views with parameters
- CDS views with DCL
- CDS view entities
- CDS view entities with parameters
- CDS view entities with DCL
- Projection views
Related Information
63 Comments