ERPClimb logoERPClimb
EML
RAP / CDS / ODataadvanced 11 min read

EML Part 5: Testing RAP with EML and Transactional Consistency

Preview · a free account unlocks the full lesson

Key takeaway

Use EML to prove that a RAP business object behaves correctly and consistently: test structure, isolating tests, checking permissions and messages, testing draft and bulk behavior, and simulation for pre-checks.

In this lessonShow sections

Visual overview

EML Part 5: Testing RAP with EML and Transactional Consistency — learning sheetIn one line: Use EML to prove that a RAP business object behaves correctly and consistently: test structure, isolating tests, checking permissions and messages, testing draft and bulk behavior, and simulation for pre-checks.ERPClimb.com / RAP / LESSON 5/5 / LEARNING SHEETEML Part 5: Testing RAP with EML and TransactionalConsistency1 · IN ONE LINEUse EML to prove that a RAP business object behaves correctly and consistently: teststructure, isolating tests, checking permissions and messages, testing draft and bulkbehavior, and simulation for pre-checks.2 · KEY IDEAS EXPLAINEDWhy EML Is The Right Test InterfaceOData, Fiori and other BOs all end up in the sameRAP runtime that EML uses. A test that creates,changes and commits via EML exercises the real…A Good Test StructureArrange: prepare input with %cid; set up testdoubles for data the BO reads (e.g. suppliermaster data).Act: one EML operation (or a short sequence) —MODIFY, EXECUTE, COMMIT ENTITIES RESPONSE.What To Test — A ChecklistEach validation: one passing and one failing case,including the message and field.Each determination: result correct; idempotent(trigger twice, same result).IsolationTests whose save succeeds write to the database.Use the ABAP SQL test double framework(cl_osql_test_environment) to redirect your tables…For other BOs your code calls, use RAP BO testdoubles where your release provides them, or wrapthe call in an interface you can replace in tests.3 · DO · AVOIDBest practice!Common mistakeArrange–Act–Assert with EML; commit whensave-phase rules matter.Isolate with SQL test doubles and BO testdoubles.Cover validations, determinations(idempotency), actions, feature control, draft…✕Tests that only MODIFY and never commit, sovalidations are never exercised.✕Tests depending on existing data in thedevelopment system.✕No teardown with ROLLBACK ENTITIES, so testsinfluence each other.4 · IN A REAL PROJECTA team discovered a validation that only failed during save because it checked the combination of header anditems — but their tests only called MODIFY and never COMMIT ENTITIES, so the validation never ran in tests.Bad data was caught only by users in QAS. They reworked the test class: every validation test now ends with…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

By now EML can be used fluently, as covered across Parts 1 through 4. The last step is using it to verify behavior automatically. Behavior Implementations Part 5 introduced unit tests; this lesson goes further into what to test and how to keep those tests reliable.

EML is the right test interface because OData, Fiori and other BOs all ultimately end up in the same RAP runtime that EML itself uses. A test that creates, changes and commits via EML exercises the real behavior — authorization, feature control, determinations, validations, draft — without needing a UI at all, and such tests stay fast, repeatable, and suitable for CI.

A good test follows a consistent structure. Arrange by preparing input with %cid and setting up test doubles for any data the BO reads, such as supplier master data. Act with one EML operation, or a short sequence of them — MODIFY, EXECUTE, COMMIT ENTITIES RESPONSE. Assert against FAILED and %fail-cause, against REPORTED messages (severity, number, %element), and against data read back with READ ENTITIES. Tear down with ROLLBACK ENTITIES. Each test method should cover one behavior, with descriptive names such as "approve_rejected_in_status_new".

A useful checklist for what to test: each validation should have one passing and one failing case, including the message and the field it targets; each determination should be checked for a correct result and for idempotency, by triggering it twice and confirming the same result; each action should be tested in both allowed and disallowed states, checking the returned result and messages; feature control should be checked by confirming GET PERMISSIONS returns the expected enabled or disabled values per status; authorization should be run with a test user, or with test doubles for authority checks where the release supports them; draft should be tested by creating a draft (%is_draft = mk-on), changing it, executing Prepare and Activate, and verifying the active instance; bulk behavior should be tested with 100 to 500 instances in one call, checking for no failures and acceptable runtime; and cross-BO calls should have calls to other BOs replaced by test doubles, so that only your own logic is actually being tested.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

Keep exploring

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.