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

Lesson 3 of 5

Testing side-by-side extensions

18 min

Listen to this lesson

0:00 / 7:43

Side-by-side extensions run on SAP BTP and talk to S/4HANA through APIs and events. They are decoupled from the core by design, which makes them upgrade-friendly, but it moves the risk to the boundary: the API contract, authentication, network and data mapping. Testing them well means testing the app on its own, testing the boundary explicitly, and testing a few real end-to-end flows.

Every arrow between the warranty app and S/4HANA is a boundary the app depends on, which is where side-by-side testing must focus.
The Sign-Off Table · thesignofftable.com/academy/sap-tst-402

Service tests in CAP

CAP has built-in test support. Developers add the @cap-js/cds-test package and use cds.test to start a CAP server for the project inside the test, then call its services with HTTP helpers such as GET and POST, with mock users for authentication. Tests run with Node.js's built-in test runner or other common JavaScript runners. By default the server uses an in-memory database, and a data reset before each test keeps tests independent. Services can also be called programmatically, without the HTTP layer, to test logic directly.

End-to-end testsA few critical flows against a connected S/4HANA quality system
Contract testsThe app's expectations checked against the API specification and the real API
Service testsCAP services over HTTP with cds.test, mock users and in-memory data
Unit testsPure functions: claim rules, mappings, validations
A test layering for a side-by-side CAP extension.
The Sign-Off Table · thesignofftable.com/academy/sap-tst-402

Mocking S/4HANA, carefully

To develop and test without a live S/4HANA, CAP lets you import an API definition (for example an EDMX file from the SAP Business Accelerator Hub) with cds import. During local development CAP mocks imported services automatically, running them in-process with the app's in-memory database, or in a separate process with cds mock. That makes the inner development loop fast and lets the integration logic be built in parallel. The CAP documentation also warns against overdoing it: the more you mock, the less you test the real thing.

So a mock is only as good as its fidelity to the real API. If the mock returns a field the real API doesn't, or accepts a filter the real API rejects, every service test passes and production fails. That is the gap contract tests close.

Contract tests

A contract test checks the agreement between consumer and provider rather than either side's full behavior. For Contoso's portal, the contract is the subset of the S/4HANA API it relies on: entity sets, properties, keys, filters and the error behavior it handles. Two checks keep that contract honest:

  1. Specification check: compare the consumer's expectations (fields, types, operations) with the provider's published specification, such as the OData metadata of the API version in the target system. Run it whenever either side changes.
  2. Provider verification: run a small set of requests against the real API in a quality system and assert the response shape and key semantics the consumer depends on.
Mocks speed up service tests, and contract checks against both the specification and the real API keep those mocks honest.
The Sign-Off Table · thesignofftable.com/academy/sap-tst-402
ApproachFindsMisses
Service tests with mocksLogic errors in the app, fastAny difference between mock and real API
Contract testsBreaking changes in fields, types, operations and errorsBusiness process problems across systems
End-to-end testsReal flow including authentication, network and dataLittle, but slow, brittle and expensive to run often
Each layer covers what the others miss.
The Sign-Off Table · thesignofftable.com/academy/sap-tst-402

Released APIs are designed to be stable, so contract tests on them rarely fail, which is the point: when one does, it tells you early and precisely. They matter most where the consumer depends on details beyond the stability promise (an undocumented default sort order, a field that happens to be filled) or where your own team owns the provider, such as a custom OData service built on a RAP business object.

What would you do?

All service tests of the warranty portal pass with mocked S/4HANA. In the first end-to-end test in CMQ, claim lookups fail because the real API returns the serial number in a different property than the mock. What should change in the test strategy?

Key points
  • Side-by-side extensions move risk to the boundary: API contract, authentication, network and mapping.
  • CAP's cds.test runs service tests over HTTP with mock users and in-memory data.
  • Mocks generated from imported API definitions speed development but must stay faithful to the real API.
  • Contract tests check the consumer's expectations against the provider's specification and real responses.

Check your understanding · not graded

Lesson check

  1. 1. What does cds.test do in a CAP test?

  2. 2. What risk do mocked S/4HANA services introduce?

  3. 3. What does a contract test check?

  4. 4. Where are contract tests most valuable?