عزل بيانات الاختبار
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
keep tests independent of each other.
الموضوعات المخطط لها
- Shared mutable data makes tests pass or fail depending on order.
- Options: roll back each test's transaction (
@Transactional), clean tables in@BeforeEach, or use unique data per test. @Transactionalon tests does not roll back when the code runs in another thread or via real HTTP.- Prefer unique values (random email) so tests cannot collide.
- Never rely on rows left behind by other tests.
تفاصيل المخطط المبدئي
عرض عملي
a @BeforeEach that truncates tables, and a helper uniqueEmail() returning user-<uuid>@test.com.
اختبر فهمك
Does @Transactional rollback work for a test using real HTTP calls?
أظهر الإجابة
No; the server runs in another thread and commits separately.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.