Lesson 3 of 5
Testing side-by-side extensions
18 min
Listen to this lesson
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.
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.
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:
- 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.
- 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.
| Approach | Finds | Misses |
|---|---|---|
| Service tests with mocks | Logic errors in the app, fast | Any difference between mock and real API |
| Contract tests | Breaking changes in fields, types, operations and errors | Business process problems across systems |
| End-to-end tests | Real flow including authentication, network and data | Little, but slow, brittle and expensive to run often |
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?
- 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. What does cds.test do in a CAP test?
2. What risk do mocked S/4HANA services introduce?
3. What does a contract test check?
4. Where are contract tests most valuable?