المفاتيح والإعدادات والاختبار بنموذج وهمي
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
keep secrets safe and tests deterministic.
الموضوعات المخطط لها
- API keys come from environment variables, never from
application.ymlcommitted to Git. - Reference the key as
${AI_API_KEY}in configuration. - Define an interface (
ProductDescriptionAssistant); the Spring AI class implements it. - In tests use a fake implementation that returns a fixed record. No network, no cost, same result every run.
- Test the invalid-output path with a fake that returns bad data.
تفاصيل المخطط المبدئي
عرض عملي
interface ProductDescriptionAssistant { Description describe(ProductInfo info); }
class FakeAssistant implements ProductDescriptionAssistant {
public Description describe(ProductInfo i) { return new Description("Test", "Fixed text"); }
}اختبر فهمك
Why a fake in tests?
أظهر الإجابة
Fast, free, offline, and deterministic.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.