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

Lesson 5 of 5

Testing OData services

9 min

Listen to this lesson

0:00 / 6:34

An OData service is a contract: given this request, the service returns this response and makes this change. Testing an OData service means checking every part of that contract, including the parts that go wrong. A test set that only checks a successful read of one record has tested perhaps a tenth of what a client like FleetLink depends on.

Tools

ToolGood for
SAP Gateway Client (/IWFND/GW_CLIENT)Manual calls from inside SAP S/4HANA with your own user; handles the CSRF token for you in many cases; replays error log entries
BrowserQuick GET calls such as $metadata and simple reads
RAP service binding previewFor UI bindings, a quick Fiori elements preview of the service
ABAP UnitDeveloper tests of RAP behavior (validations, actions) without HTTP
A scriptable HTTP client or test frameworkRepeatable API test suites with assertions, run in a pipeline or before each release
SAP Cloud ALMTest cases, execution results and evidence linked to requirements and defects

Tools for testing OData services. Choose automated suites for anything you will run more than twice.

What to test

Contract$metadata loads; entity sets, keys, fields and types match the agreed specification
ReadsFilters, selects, expands, sorting, paging and counts return the right data
WritesCreate, update and delete change the right data and return the right status codes
ConcurrencyETags stop an update based on stale data
SecurityAuthentication, start and business authorizations, CSRF protection
ErrorsInvalid requests return clear 4xx errors; no 500s for user mistakes
PerformanceResponse times and payload sizes at realistic volume
Seven layers of an OData test set.
The Sign-Off Table · thesignofftable.com/academy/sap-int-202

Reads. Check that $filter returns exactly the matching entities and no others, that paging with $top and $skip neither skips nor repeats records, and that $expand returns the right child entities. Compare the API result with the same data in the SAP Fiori app or SAP GUI, not with what you expect it to be.

Writes. Fetch a CSRF token, then create with POST and check for 201 Created and a document you can open in the app. Update with PATCH and confirm only the sent fields changed. Delete and confirm 204 No Content, or the business rule that forbids deletion.

Concurrency. Many services return an ETag, a version marker, with each entity. A client sends it back in an If-Match header when it updates. If someone else changed the entity in between, the ETag no longer matches and the server rejects the update with 412 Precondition Failed. Services that require an ETag reject updates without one, typically with 428 Precondition Required. Test both, because a client that ignores ETags silently overwrites other people's changes.

ETags stop lost updates: the second writer is rejected because the contract changed after it was read.
The Sign-Off Table · thesignofftable.com/academy/sap-int-202
Status codeMeaningExample test
200 / 201 / 204Success: read, created, changed or deleted with no bodyCreate a fleet contract; update its end date; delete a draft
400 Bad RequestThe request is malformed or a value is invalidFilter on a property that does not exist; end date before start date
401 UnauthorizedNot authenticatedCall without credentials
403 ForbiddenAuthenticated but not allowed, or CSRF token missingPOST without a token; user without the role
404 Not FoundEntity or service does not existRead a contract number that does not exist
412 / 428ETag mismatch / ETag required but missingUpdate with an old ETag; update with no If-Match header
500 Internal Server ErrorThe server failedShould never be the answer to a user mistake; raise a defect
Status codes every OData test set should cover.
The Sign-Off Table · thesignofftable.com/academy/sap-int-202

Error handling. SAP Gateway returns errors in a structured body with a code and a message, and RAP services pass validation messages back the same way. Test that the message is one a portal user or support analyst can act on. "Contract end date must be after start date" is good; a short dump reference is a defect.

The FleetLink regression pack runs after every transport import into CMQ and in CMR before every upgrade, and every run leaves evidence in SAP Cloud ALM.
The Sign-Off Table · thesignofftable.com/academy/sap-int-202

What would you do?

An automated test updates a fleet contract with PATCH and gets 412 Precondition Failed. The developer says the test is flaky. What is the most likely explanation?

Key points
  • Test the whole contract: metadata, reads, writes, concurrency, security, errors and performance.
  • Writes need a CSRF token; check status codes and the resulting document in the app.
  • ETags with If-Match prevent lost updates; test 412 and 428 behavior.
  • Automate API regression tests and run them after transports and before upgrades.

Check your understanding · not graded

Lesson check

  1. 1. Which status code means an update was rejected because the ETag no longer matches?

  2. 2. Which tool lets you test an OData call from inside SAP S/4HANA with your own user?

  3. 3. A user mistake in a request returns 500 Internal Server Error. How should you treat it?