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

Arrange-Act-Assert والتسمية

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

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

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

في هذا الدرس

structure each test so it reads in seconds.

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

  • Arrange: set up data and collaborators. Act: call the thing under test once. Assert: check the outcome.
  • Separate the three parts with blank lines or comments.
  • Name tests by behavior: rejectsOrderWhenStockIsZero, not test1 or placeOrderTest.
  • One reason to fail per test; a name with "and" often means two tests.
  • Assert on outcomes, not on how the code got there.
تفاصيل المخطط المبدئي

عرض عملي

java
@Test
void rejectsOrderWhenStockIsZero() {
    var product = aProduct().withStock(0).build();       // arrange
    var result = service.place(orderOf(product));         // act
    assertThat(result.status()).isEqualTo(REJECTED);      // assert
}

اختبر فهمك

What does the "Act" step do?

أظهر الإجابة

Calls the code under test, once.

التطبيق

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

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

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

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