Arrange-Act-Assert والتسمية
في هذا الدرس 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, nottest1orplaceOrderTest. - One reason to fail per test; a name with "and" often means two tests.
- Assert on outcomes, not on how the code got there.
تفاصيل المخطط المبدئي
عرض عملي
@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.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.