انتقل إلى المحتوى
أمين أبوزيد
MID-045

الاختبار المتقدم

  • 6 درس
  • 3 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • اختبار العقود (Contract Testing)
  • العقود الموجّهة بالمستهلك
  • الاختبار القائم على الخصائص (Property-based Testing)

تعلّم أولًا

3 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Explain why end-to-end tests across many services are slow and brittle.
  2. Write consumer-driven contract tests for HTTP and messaging (Pact or Spring Cloud Contract).
  3. Verify provider contracts in CI and block breaking changes.
  4. Write property-based tests (jqwik) for domain invariants.

الدروس

  1. 01اختبار الأنظمة الموزّعة
  2. 02العقود الموجّهة بالمستهلك
  3. 03العقود للرسائل
  4. 04العقود في CI
  5. 05الاختبار القائم على الخصائص
  6. 06عرض عملي: تغيير API كاسر يكشفه عقد

المختبر والتمارين

Lab

MID-045-LAB1 · Contracts for Shop

Outcomes: 1–4 · Time: ~3 h Write contracts between orders and inventory (HTTP) and for OrderPlaced (Kafka), verified in both pipelines. Add jqwik property tests for the Order aggregate. Acceptance: renaming a field fails the provider build.

Exercises (assessment: lab plus a test-strategy question)

IDOutcomeTask
MID-045-EX011List the problems of an end-to-end test that places an order across four services; propose which checks move lower.
MID-045-EX022Write a consumer test in orders producing a Pact (or Spring Cloud Contract) for GET /stock/{sku}.
MID-045-EX032Rewrite a contract that asserts a whole response body so it matches only the fields used.
MID-045-EX042Write a message contract for OrderPlaced and verify it in the producer.
MID-045-EX053Add contract verification to the provider pipeline so a failure blocks the build.
MID-045-EX064Write two jqwik properties for the Order aggregate (total equals sum of lines; total never negative).
MID-045-EX071–3Test-strategy question: for a new payments service called by orders, state which tests you write at each level and why.
أظهر الحلول
  • EX01 Slow, brittle, hard to diagnose; move validation to unit tests, interactions to contract tests, DB behavior to Testcontainers; keep one smoke test.
  • EX02 Define the interaction (request, response with sku string and available integer) in the consumer test; the generated file is published.
  • EX03 Replace exact body matching with type matchers on sku and available only.
  • EX04 Message contract with orderId and totalCents; the provider test builds the real event and checks it against the contract.
  • EX05 Pipeline step runs provider verification against published contracts; non-zero exit fails the job.
  • EX06 @Property with a generator of valid orders; assertions as in the lecture; second property: total() >= 0.
  • EX07 Unit tests for payment rules, consumer contract with payments, Testcontainers for persistence, a smoke test; end-to-end only for the happy path.

Outcome 3 is also checked by lab criterion "renaming a field fails the provider build".

الاختبار

Outcomes: O1 limits of end-to-end tests · O2 consumer-driven contracts · O3 contracts in CI · O4 property-based tests.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1A main weakness of end-to-end tests across many services:O1
  2. 2Most checks should be:O1
  3. 3In a consumer-driven contract, the expectations come from:O2
  4. 4A contract should assert:O2
  5. 5Message contracts apply to:O2
  6. 6The provider verifies contracts:O3
  7. 7The provider renames a field a consumer uses. Result:O3
  8. 8Safe way to remove a field:O3
  9. 9A property-based test:O4
  10. 10Shrinking in jqwik:O4

الجزء العملي

Seven exercises MID-045-EX01 to EX07 (EX07 is the test-strategy question) plus the contracts lab. Pass: at least five exercises and a lab where renaming a field fails the provider build.

أخطاء شائعة

Contracts written by the provider alone; asserting entire payloads.

التقييم

Lab plus test-strategy question.

الصلة بالمسار الوظيفي

API evolution (MID-062) and quality strategy at Staff level.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.