Software Testing Engineering / API & CONTRACT TESTING / TST-020
Suggested study path · Step 5 of 5 · G1
Contract Drift
Explore concept graphMateri
Masalah: API transfer masih mengembalikan 201, tetapi refactor mengubah field JSON dan mematahkan consumer yang bergantung pada kontrak lama.
Mulai: baca delapan field wajib di schema Transfer dari kontrak SYS-008.
SYS-008 OpenAPI
|
Transfer baseline
|
+-- Schema diff: required / type change --> fail
|
+-- Payload diff: missing / number / enum --> fail
|
+-- Optional memo
| |
tolerant strict legacy
accepts rejectsMatrix perubahan kontrak
| Perubahan | Hasil yang diharapkan |
|---|---|
| Hapus currency dari required | Breaking guarantee |
| Ubah amount dari string menjadi number | Breaking type |
| Jadikan memo baru required | Breaking untuk respons lama |
| Tambah memo opsional | Kandidat kompatibel untuk consumer toleran |
| Hilangkan currency dalam body atau kirim EUR | Invalid terhadap baseline |
Konsep 1 / 3
Detect removed required response guarantees against an older provider contract.
An older client can rely on currency being present even when a new schema makes it optional.
Compare Transfer.required across the tracked baseline and a cloned candidate.
Intuisi utama
Response compatibility flows from provider guarantees toward existing clients.
Removing currency from required weakens the old provider guarantee. A new response missing currency may fail an older consumer despite the new schema validating it.
Contoh bertahap
A Transfer schema drops currency from its required list but leaves it in properties.
- Compare Transfer.required across the tracked baseline and a cloned candidate.
Mengapa: An older client can rely on currency being present even when a new schema makes it optional.
Hasil yang diharapkan: A missing required guarantee is rejected.
Konsep 2 / 3
Detect breaking type changes and malformed response instances independently.
A numeric JSON amount can break existing clients expecting a decimal string.
Mutate a cloned schema amount.type and a separate cloned response amount value.
Intuisi utama
Schema diff catches changed promises while instance validation catches nonconforming emitted data.
Transfer.amount is a string. Changing the declared type to number breaks the contract; sending a numeric value under the original schema violates it. Missing currency and invalid EUR must also fail.
Contoh bertahap
The response sends numeric amount despite the unchanged string schema.
- Mutate a cloned schema amount.type and a separate cloned response amount value.
Mengapa: A numeric JSON amount can break existing clients expecting a decimal string.
Hasil yang diharapkan: Both schema change and payload mutation are rejected.
Konsep 3 / 3
Test optional field additions with both tolerant and strict legacy consumers.
A green schema diff is not a guarantee every deployed client accepts unknown properties.
Add memo as a non-required property and validate it with tolerant and strict consumers.
Intuisi utama
Optional additive evolution is conditional on the actual consumer's unknown-field handling.
Transfer has additionalProperties true. Adding optional memo preserves the eight required fields and passes a tolerant old schema. A deliberately strict legacy consumer rejects memo, proving consumer review remains necessary.
Contoh bertahap
A new optional memo field is added to an otherwise unchanged Transfer response.
- Add memo as a non-required property and validate it with tolerant and strict consumers.
Mengapa: A green schema diff is not a guarantee every deployed client accepts unknown properties.
Hasil yang diharapkan: Tolerant response passes while strict consumer rejects unknown memo.
Sumber primer
Sumber
Cross-domain connections
Curated relationships for this unit at G1. Proposed edges are suggestions, not prerequisites.
Dashed = proposed relationship; solid = reviewed connection. Only reviewed prerequisites constrain a learning path. Keyboard and text links remain available.