Lesson 2 of 5
Mapping and contract tests
10 min
Listen to this lesson
Mapping defects are the most common integration defects, and the cheapest to find before partners are involved. Contract defects, where the two sides simply disagree about the message, are the most expensive to find late, because each side's tests pass on its own. This lesson covers both.
Mapping tests
A mapping test feeds a known input message into one mapping and compares the output with an expected message, field by field. It needs no partner, no connected system and often no deployed flow. The test set is a library of input and expected-output pairs, derived from the mapping specification and real (scrambled) samples, stored in version control with the integration content.
- Every mapped field at least once, compared at the target, not just "the message arrived".
- Multi-item messages with different values per item, to catch context errors that repeat or drop item values.
- Boundaries: longest allowed field lengths, decimals and rounding, dates at month end and year end, time zones.
- Value mappings: every entry, plus one value that is not in the table.
- Optional and empty fields: absent, empty and whitespace, which mappings often treat differently.
- Character sets: accented names such as those Contoso will meet in Monterrey, and special characters in free text.
How you run them depends on the technology. Message mappings and scripts in Cloud Integration can be exercised with sample payloads in a test tenant with receivers stubbed; depending on your tenant, the flow editor may also let you simulate parts of a flow with a sample payload. Groovy scripts can be unit tested outside the tenant like any other code. On the S/4HANA side, ABAP logic in exits or AIF actions can be covered with ABAP Unit, SAP's unit test framework, which Kenji's team already uses.
- SpecificationMapping specification lists fields, rules and value mappings for the Lakeside order.
- SamplesScrambled real ORDERS IDocs plus derived variants, one change per variant.
- Expected outputsWritten from the specification and reviewed by the business analyst, not generated from the mapping itself.
- Automated runEach pair run through the mapping after every change; outputs compared field by field.
- EvidencePass list per version stored with the flow; failures become defects with the sample attached.
Contract tests
A contract is the agreement between a producer and a consumer about a message: structure, data types, mandatory fields, allowed values, and for APIs the operations and responses. In SAP landscapes, contracts take several forms: an IDoc basic type with extensions, an XML schema (XSD) for a partner format, an OpenAPI description for an HTTP API. A contract test checks one side against the agreed contract without needing the other side: does the producer's output validate against it, and does the consumer accept every valid variant?
| Contract form | Producer-side test | Consumer-side test |
|---|---|---|
| IDoc type and extension | Outbound IDocs carry the agreed segments and mandatory fields | Inbound processing accepts every valid variant and rejects invalid ones clearly |
| XSD for a partner format | Mapping output validates against the partner's schema | Partner confirms acceptance of a shared sample set |
| OpenAPI for an API | Responses match documented fields, types and status codes | Consumer handles every documented response, including errors |
The most valuable habit is versioning the contract and the shared samples and running the contract tests whenever either side changes. When Lakeside upgrades its order intake and adds a mandatory field, a contract test against their new schema fails in Contoso's pipeline the day the new schema is shared, not on cutover weekend.
What would you do?
Contoso's mapping tests for the Lakeside order all pass. In the first connected test, Lakeside rejects every order because a date field uses a different format from the one in their schema. What does this reveal about the test strategy?
- Mapping tests compare outputs field by field for every variant, boundary and value-mapping gap.
- Expected results come from the specification, never from running the mapping under test.
- Contracts include IDoc types, XSDs and OpenAPI descriptions; each side tests itself against them.
- Version contracts and samples; rerun contract tests whenever either side changes.
Check your understanding · not graded
Lesson check
1. What does a mapping test compare?
2. Why are multi-item messages essential in mapping tests?
3. Which is an example of a contract in an SAP landscape?
4. Which SAP framework covers unit tests of ABAP logic used by an interface?