Now accepting guest editorial from SAP, Oracle, Workday and ServiceNow practitioners.Pitch a guide
The Sign-Off Table

Lesson 1 of 6

What to test in a RAP BO and at which layer

11 min

Listen to this lesson

0:00 / 17:55

Contoso Motor Co.'s core return agreement app is live in CMQ. Kenji's team built it as a managed, draft-enabled RAP business object, ZR_CMC_CoreAgreement with its item entity ZR_CMC_CoreAgreementItem, the behavior pool ZBP_R_CMC_COREAGREEMENT and the OData V4 UI service ZUI_CMC_COREAGREEMENT_O4. The prerequisite courses showed the BO and named the test doubles. This course is about the code: how to write the tests, which framework to use for which rule, and what Priya, the test lead, should demand before the app moves to CMP.

The first decision is not how to test but where. A RAP BO has several layers, and each layer has a test style that proves it best. Testing everything through the Fiori UI is slow and fragile; testing everything with isolated handler tests misses how determinations and validations interact in the save sequence. A good RAP test suite uses each layer for what only that layer can prove.

The layers and what each test proves

Fiori elements UISide effects, field control in the UI, draft resume across sessions: tested by people or UI automation in CMQ
OData V4 serviceWhat the projection exposes: OData client proxy tests and $metadata checks
BO scenario (EML)Create, update, action and commit together: EML scenario tests with CDS and SQL test doubles
Behavior handlersOne validation, determination, action or feature method: unit tests with the transactional buffer double
CDS view logicCalculations and filters in view entities: CDS test environment
Each layer of Contoso's agreement app, and the test style that proves it.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-304

In SAP's terms these are unit tests and integration tests. SAP's RAP100 unit testing tutorial builds a test class that calls the BO with EML, commits, and checks the persisted result against test doubles. The ABAP Unit cheat sheet from SAP adds the narrower style: calling a handler method directly while the RAP BO test double framework replaces the transactional buffer. This course calls the first an EML scenario test and the second a handler unit test.

Mapping behavior to tests

BDEF elementContoso examplePrimary testSecond test
Validation on savevalidateDates: ValidTo must be after ValidFromHandler unit test: invalid key in failed, message on ValidToEML scenario: COMMIT ENTITIES fails, sy-subrc 4
Determination on modifysetInitialStatus sets Status OPENEML scenario: create without Status, read back OPENHandler unit test if logic branches
Determination on savecalcTotalDeposit sums item depositsEML scenario: two items, total after commitHandler unit test for rounding
ActioncloseAgreement sets Status CLOSEDHandler unit test: result returned, Status CLOSEDEML scenario: action then commit
Instance feature controlNo update or delete on CLOSEDEML: GET PERMISSIONS, or attempt and check failedUI check in CMQ
AuthorizationOnly 1910 users change 1910 agreementsHandler test with restricted authorizationsRole test with real users in CMQ
Draft and PrepareValidations assigned to PrepareEML scenario on a draft instanceResume across sessions in CMQ
Side effectsQuantity refreshes DepositAmountNot ABAP Unit: $metadata and UI checkUI automation

Contoso's test map for the agreement BO: every behavior element has a primary test at the cheapest layer that can prove it.

Kenji's rule for choosing a layer: test each rule at the cheapest layer that can prove it, then cover the main paths once more in an EML scenario.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-304

Two phases, two kinds of failure

Remember the RAP split between the interaction phase and the save sequence. In the interaction phase, MODIFY ENTITIES changes the transactional buffer and determinations on modify run. On COMMIT ENTITIES, the save sequence runs: determinations on save, validations in check_before_save, then the actual save. The ABAP keyword documentation is precise about the return code: sy-subrc 4 means the failure happened in the early save phase and the responses are in failed; 8 means the late save phase failed and an explicit ROLLBACK ENTITIES is required.

A test can assert at two points: after MODIFY ENTITIES for interaction-phase behavior and after COMMIT ENTITIES for save-phase behavior.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-304

A common blind spot follows from this. A test that only runs MODIFY ENTITIES and checks failed is empty never runs a single validation, because validations on save fire only at commit. Kenji's code review checklist asks: "Which phase does this test assert?" If the answer is "interaction only", the validations are untested.

What goes wrong in testing

  • Testing through the UI only. Maria's team found that closed agreements could still be edited through the API, because nobody tested feature control below the UI.
  • No commit, no validation. Tests that stop after MODIFY ENTITIES pass while validateDates is broken.
  • Real data in CMD. Tests that read an agreement someone keyed in months ago fail after a client refresh.
  • IN LOCAL MODE everywhere. Calling the BO in local mode from a test skips feature and authorization control, so the test proves less than it seems.
UI scripts in CMQSlow and broad; kept for acceptance only
EML scenario tests with doublesIsolated from data; prove handlers together
OData tests on real dataFast enough but fragile after refreshes
Handler unit testsFastest and most isolated; one rule each
Where Contoso's first test inventory sat, and where it needed to move.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-304

What would you do?

Kenji's team has 14 handler unit tests for the agreement BO, all green, and no EML scenario tests. Priya asks whether that is enough for the build-phase exit. What should she ask for?

Key points
  • Test each RAP rule at the cheapest layer that can prove it, then cover main paths again in an EML scenario.
  • Validations on save run only at COMMIT ENTITIES; a test without a commit does not test them.
  • sy-subrc 4 after COMMIT ENTITIES means an early save failure; 8 needs an explicit ROLLBACK ENTITIES.
  • Side effects and draft resume are UI behavior: test them in CMQ, not with ABAP Unit.

Check your understanding · not graded

Lesson check

  1. 1. Which test proves that determinations and validations work together in the save sequence?

  2. 2. A test runs MODIFY ENTITIES and asserts that failed is empty. What has it not tested?

  3. 3. What does sy-subrc 4 after COMMIT ENTITIES mean?

  4. 4. Where should Contoso test that Quantity refreshes DepositAmount on screen?

  5. 5. Why is testing only through the Fiori UI risky for a RAP BO?