Lesson 5 of 5
Testing OData services
9 min
Listen to this lesson
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
| Tool | Good 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 |
| Browser | Quick GET calls such as $metadata and simple reads |
| RAP service binding preview | For UI bindings, a quick Fiori elements preview of the service |
| ABAP Unit | Developer tests of RAP behavior (validations, actions) without HTTP |
| A scriptable HTTP client or test framework | Repeatable API test suites with assertions, run in a pipeline or before each release |
| SAP Cloud ALM | Test 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
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.
| Status code | Meaning | Example test |
|---|---|---|
| 200 / 201 / 204 | Success: read, created, changed or deleted with no body | Create a fleet contract; update its end date; delete a draft |
| 400 Bad Request | The request is malformed or a value is invalid | Filter on a property that does not exist; end date before start date |
| 401 Unauthorized | Not authenticated | Call without credentials |
| 403 Forbidden | Authenticated but not allowed, or CSRF token missing | POST without a token; user without the role |
| 404 Not Found | Entity or service does not exist | Read a contract number that does not exist |
| 412 / 428 | ETag mismatch / ETag required but missing | Update with an old ETag; update with no If-Match header |
| 500 Internal Server Error | The server failed | Should never be the answer to a user mistake; raise a defect |
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.
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?
- 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. Which status code means an update was rejected because the ETag no longer matches?
2. Which tool lets you test an OData call from inside SAP S/4HANA with your own user?
3. A user mistake in a request returns 500 Internal Server Error. How should you treat it?