Lesson 2 of 5
Testing on-stack extensions
10 min
Listen to this lesson
On-stack extensions run inside SAP S/4HANA: ABAP Cloud development such as RAP business objects and CDS views, key user extensions, and classic ABAP carried over from ECC. The cheapest place to catch their defects is the developer's own automated tests, which run in seconds and need no test system data. Business tests still matter, but they should confirm the process, not discover that a validation was never written.
Three layers of tests
ABAP Unit with test doubles
ABAP Unit tests live in test classes defined FOR TESTING with a risk level and duration (for example RISK LEVEL HARMLESS DURATION SHORT). Developers run them in ABAP Development Tools. Good unit tests do not depend on whatever data happens to be in the development client. SAP provides test environments that replace dependencies with doubles:
- CDS test environment (
cl_cds_test_environment): creates test doubles for the CDS entities a view or business object reads, so the test controls the data. - ABAP SQL test environment (
cl_osql_test_environment): replaces database tables accessed by ABAP SQL, including those written by the code under test. - Setup and teardown: environments are created once per test class, doubles are cleared and test data inserted before each test, and changes are discarded afterwards.
Testing RAP business objects
SAP's RAP unit-testing tutorial shows the pattern for a business object. The test class uses the CDS test environment for the BO's CDS entities and the ABAP SQL test environment for dependent tables. A test method calls the BO through EML (MODIFY ENTITIES) to create an instance and execute actions, checks the FAILED, REPORTED and MAPPED results, persists with COMMIT ENTITIES into the doubles, and verifies the stored result. ROLLBACK ENTITIES in teardown discards changes. A test relation in ABAP Doc lets the tests run from the behavior definition.
- class_setupCreate CDS and ABAP SQL test environments
- setupClear doubles; insert test data (for Contoso, a core return agreement for Great Lakes Fleet Services)
- ActMODIFY ENTITIES: create, then execute an action such as approving the return
- AssertCheck FAILED, REPORTED and MAPPED; COMMIT ENTITIES; read back and compare
- teardownROLLBACK ENTITIES; class_teardown destroys the environments
What each extension type needs
| Extension | Developer tests | Integration and business tests |
|---|---|---|
| RAP business object (level A) | ABAP Unit through EML: validations, determinations, actions, authorization checks | App test in QAS with real roles; process test end to end |
| CDS view for analytics | CDS test doubles with edge-case data (empty, multi-currency, cancelled documents) | Reconcile totals with a trusted report in QAS |
| Key user extension (custom field, custom logic) | Limited; test the logic through the app | Field flow through follow-on documents; positive and negative cases |
| Classic ABAP (level B/C) | ABAP Unit where the code allows it; often needs refactoring first | Regression of every process that calls it |
| Modification (level D) | Rarely unit-testable | Full process regression after every adjustment |
Test responsibilities by on-stack extension type.
Note the pattern: the cleaner the extension, the more of its testing can move down into fast developer tests. Legacy code usually lacks seams for test doubles, so its tests stay at the expensive top layer. That is part of the business case for remediation: rebuilding a level C report on released CDS views makes it both upgrade-stable and unit-testable.
What would you do?
Kenji's developer delivers the core return agreement app with no ABAP Unit tests, saying "Maria will test it in CMQ." What should Priya ask for?
- Put most on-stack tests at the developer layer: ABAP Unit with CDS and ABAP SQL test doubles.
- Test RAP business objects through EML; check FAILED, REPORTED and MAPPED and the committed result.
- Key user extensions and legacy code rely more on integration and business tests.
- Cleaner extensions are easier to unit test, which strengthens the case for remediation.
Check your understanding · not graded
Lesson check
1. Which SAP class creates test doubles for CDS entities in ABAP Unit?
2. How does a unit test exercise a RAP business object?
3. Why use test doubles instead of client data in unit tests?
4. Which extension type usually needs full process regression after each adjustment?