عرض عملي: حقن Clock لاختبار منطق يعتمد على الوقت
في هذا الدرس 3 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
make "is the sale active now?" testable; prepares JNR-010-LAB1.
تفاصيل المخطط المبدئي
خطوة بخطوة
- Show
PromotionServicecallingLocalDate.now(); the test passes only on certain days. - Add a
Clockbean in a@Configurationclass. - Inject
Clockthrough the constructor and useLocalDate.now(clock). - Planned mistake: leave one static
Instant.now()in another service; the test still flakes. Fix: search fornow()and replace. - In the test use
Clock.fixed(...)and assert both sides of the deadline.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.