انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهJNR-043-L02

دورة الحياة والبنية

  • الدرس 2 من 6
  • Junior
في هذا الدرس 4 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

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

في هذا الدرس

use the JUnit Jupiter lifecycle annotations to keep tests tidy.

الموضوعات المخطط لها

  • @BeforeEach runs before every test; @AfterEach runs after every test. JUnit makes a fresh test-class instance per test, so tests do not share fields.
  • @BeforeAll / @AfterAll run once per class and are static by default.
  • @DisplayName gives a readable name in reports.
  • @Nested groups tests by situation (for example "when the cart is empty").
  • @Disabled skips a test, but always with a reason.
تفاصيل المخطط المبدئي

عرض عملي

java
@DisplayName("Cart")
class CartTest {
    Cart cart;
    @BeforeEach void setUp() { cart = new Cart(); }

    @Nested @DisplayName("when empty")
    class WhenEmpty {
        @Test void totalIsZero() { assertEquals(BigDecimal.ZERO, cart.total()); }
    }
}

اختبر فهمك

How many times does @BeforeEach run for a class with four tests?

أظهر الإجابة

Four.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

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

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

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