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

Lesson 2 of 5

Mapping and contract tests

10 min

Listen to this lesson

0:00 / 14:20

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.

  1. SpecificationMapping specification lists fields, rules and value mappings for the Lakeside order.
  2. SamplesScrambled real ORDERS IDocs plus derived variants, one change per variant.
  3. Expected outputsWritten from the specification and reviewed by the business analyst, not generated from the mapping itself.
  4. Automated runEach pair run through the mapping after every change; outputs compared field by field.
  5. EvidencePass list per version stored with the flow; failures become defects with the sample attached.
A mapping test library for one Contoso interface.
The Sign-Off Table · thesignofftable.com/academy/sap-int-302
Where expected results come from decides whether a mapping test can fail: from the specification it can, from the mapping's own output it cannot.
The Sign-Off Table · thesignofftable.com/academy/sap-int-302

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 formProducer-side testConsumer-side test
IDoc type and extensionOutbound IDocs carry the agreed segments and mandatory fieldsInbound processing accepts every valid variant and rejects invalid ones clearly
XSD for a partner formatMapping output validates against the partner's schemaPartner confirms acceptance of a shared sample set
OpenAPI for an APIResponses match documented fields, types and status codesConsumer handles every documented response, including errors
Contract tests by contract form. Each side tests itself against the shared contract.
The Sign-Off Table · thesignofftable.com/academy/sap-int-302

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.

A versioned contract catches Lakeside's new mandatory field on the day the schema is shared, weeks before any connected test.
The Sign-Off Table · thesignofftable.com/academy/sap-int-302

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?

Key points
  • 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. 1. What does a mapping test compare?

  2. 2. Why are multi-item messages essential in mapping tests?

  3. 3. Which is an example of a contract in an SAP landscape?

  4. 4. Which SAP framework covers unit tests of ABAP logic used by an interface?