Software Testing Engineering / API & CONTRACT TESTING / TST-021

Mock Bank Contract

Explore concept graph

Latihan soal

Real Pact JS laboratory

Jalankan Node 24 pada root repository:

npm install --prefix labs/TST-021 --no-audit --no-fund --package-lock=false
node labs/TST-021/pact-contract.mjs

Gunakan Pact JS 17.1.4 yang dideklarasikan oleh lab. Urutan bukti:

  • Consumer menjalankan fungsi HTTP client terhadap mock server Pact, menghasilkan file Pact.
  • Verifier memutar ulang success 200 dan error 404 terhadap local HTTP server yang sehat.
  • Provider kedua mengubah amount string menjadi number; Pact harus mengembalikan verification failure yang diassert oleh negative test.

Generator V3 tidak mengklaim menjalankan Pact: dependency native dijalankan secara terpisah di CI. Lab menulis kontrak ke direktori sementara, bukan ke database atau file user. Tidak perlu Pact Broker untuk demonstrasi lokal ini.

Konsep 1 / 3

Define one real Pact consumer contract for the transfer 200 success and a stable 404 error.

Coba prediksi atau perbaiki

Should a Pact consumer test call its real client function, or issue arbitrary fixture-only requests?

Kalau jawabanmu berbeda

Kesalahan yang mungkin: Copying the provider's implementation code into the consumer expectation.

Mengapa tidak bekerja: The contract would then confirm the provider's current behavior rather than what the client needs.

Coba perbaiki: Define only the fields the consumer reads, and exercise the client through the mock.

Periksa hasil sendiri

Hasil yang diharapkan: Pact emits the consumer/provider contract containing one success and one error interaction.

Kalau berbeda: Verify both Pact interactions were generated, rather than validating only a JSON file name.

Konsep 2 / 3

Replay the generated Pact through the real Pact provider verifier against a local HTTP provider.

Coba prediksi atau perbaiki

Does a green Pact consumer mock test prove the deployed bank provider implements the same contract?

Kalau jawabanmu berbeda

Kesalahan yang mungkin: Treating a successfully generated Pact JSON file as proof of provider compatibility.

Mengapa tidak bekerja: File generation proves consumer expectations were captured, not that a real provider meets them.

Coba perbaiki: Launch the service and run verifier with pactUrls, observing each HTTP request.

Periksa hasil sendiri

Hasil yang diharapkan: The healthy local provider handles both expected interactions and verification succeeds.

Kalau berbeda: Check the provider state name, port, response media type and exact returned field types.

Konsep 3 / 3

Catch a breaking provider amount type mutation before allowing a release.

Coba prediksi atau perbaiki

Can an HTTP 200 response with amount numeric pass the Pact when the consumer expects a string?

Kalau jawabanmu berbeda

Kesalahan yang mungkin: Treating the CI's successful run as evidence the deliberately broken provider also passed.

Mengapa tidak bekerja: The suite should succeed by observing and asserting the bad provider's expected verification failure.

Coba perbaiki: Assert a healthy pass and an isolated negative failure from the same contract.

Periksa hasil sendiri

Hasil yang diharapkan: Healthy provider passes, the changed amount type fails under Pact verifier.

Kalau berbeda: Inspect whether the verifier actually replayed the success interaction, and ensure any failure is due to the intentional schema mismatch.

Lima soal consumer-driven contract

Jawab tanpa melihat pembahasan dulu. Kamu bisa memperbaiki jawaban dan mencoba lagi. Kuis ini latihan mandiri dan tidak menyimpan skor atau progres.

Apa yang perlu dilakukan Pact consumer test agar ekspektasinya mewakili client nyata?
Consumer Pact test berhasil menghasilkan file contract. Apakah provider sudah terbukti kompatibel?
Consumer mengharapkan amount JSON string, provider memberi number. Apa hasil yang benar?
Untuk transfer yang tidak ditemukan, field error stabil mana yang dipakai dalam lab SYS-008?
Apa cakupan yang boleh diklaim ketika Pact Verifier lokal lulus?