الاختبار المدفوع باللقطات والمعاينات
اكتشف التراجعات المرئية عبر الحالات المختلفة
الاختبار المدفوع باللقطات والمعاينات درس مجاني في SwiftUI Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في SwiftUI Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Catching Visual Bugs
Some bugs are not crashes; they are layout slips you only see. Snapshot tests catch these by comparing images of your views. 👀
How Snapshots Work
A snapshot test renders a view to an image once, saves it, then fails later if a new render no longer matches.
The Reference Image
The first run records a trusted reference image. You review it by eye, and from then on it becomes the source of truth.
Previews Drive Testing
SwiftUI previews already show a view in many states. Designing those states first makes your snapshots easy to write.
#Preview { ProfileCard(user: .sample) }Cover Many States
Add previews for empty, loading, and error states. Each one becomes a snapshot, so regressions in any state are caught.
Test Light and Dark
Render each view in light and dark mode. A color that vanishes in dark mode is exactly what a snapshot will reveal. 🌗
.preferredColorScheme(.dark)Vary Dynamic Type
Snapshot a view at the largest Dynamic Type size too. Text that overflows or clips will fail the comparison immediately.
Pin the Device Size
Always snapshot on a fixed device or frame. Different screen sizes produce different images and cause false failures.
Reading a Failure
When a snapshot fails, the tool shows old, new, and a diff. You decide: a real bug, or an intended change to re-record.
Commit Your Snapshots
Store reference images in version control. Teammates then share the same baseline, and CI can catch visual changes in pull requests.
Re-Record on Purpose
Changed the design intentionally? Switch to record mode once to refresh the baselines, then turn it off again.
Quick Check
What does a snapshot test actually compare?
Recap
You learned snapshot testing: record a reference, cover many preview states, test light and dark, and commit baselines so visual bugs never sneak in. 🎉
الأسئلة الشائعة
هل درس «الاختبار المدفوع باللقطات والمعاينات» مجاني؟
نعم — نص درس «الاختبار المدفوع باللقطات والمعاينات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة SwiftUI Academy، انتقل إلى CoddyKit PRO. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.
ماذا ستتعلم في «الاختبار المدفوع باللقطات والمعاينات»؟
اكتشف التراجعات المرئية عبر الحالات المختلفة تتمرن على SwiftUI Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ SwiftUI Academy؟
لا تُشترط خبرة سابقة. SwiftUI Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «الاختبار المدفوع باللقطات والمعاينات»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس SwiftUI Academy هذا؟
نعم. كل درس في SwiftUI Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- اختبار ViewModels اختبارًا وحداتيًا
- اختبار التعليمات البرمجية غير المتزامنة
- اختبارات واجهة المستخدم باستخدام XCUITest
- الاختبار المدفوع باللقطات والمعاينات