انتقل إلى المحتوى
أمين أبوزيد
BEG-045

أساسيات الاختبار

  • 7 درس
  • 74 دقيقة قراءة
  • 4 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

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

نظرة عامة

الموضوعات

  • ما هو الاختبار
  • حالات الاختبار
  • التأكيدات (assertions)
  • الشروط الحدّية
  • مقدمة في JUnit

تعلّم أولًا

74 دقيقة قراءة · 4 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Explain why automated tests exist and what a good test case contains.
  2. Write JUnit 5 tests with @Test, assertions, and assertThrows.
  3. Derive test cases from boundaries and equivalence classes.
  4. Run tests in the IDE and read failures.

الدروس

  1. 01لماذا نختبر آلياً11 د قراءة
  2. 02تشريح حالة اختبار10 د قراءة
  3. 03أولى اختبارات JUnit 511 د قراءة
  4. 04اختبار الاستثناءات10 د قراءة
  5. 05الحدود وفئات التكافؤ10 د قراءة
  6. 06قراءة إخفاقات الاختبار11 د قراءة
  7. 07عرض عملي: الاختبار أولاً على دالة السحب في البنك11 د قراءة

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

Lab

BEG-045-LAB1 · Test what you built

Outcomes: 1–4 · Time: ~4 h

  1. Add JUnit 5 to the project through IntelliJ's library prompt.
  2. Write tests for MyArrayList (empty, one item, resize, bad index), MyHashMap (put, replace, missing key, many keys), and the bank's withdraw (boundaries and exceptions).
  3. Name each test by behavior and follow Arrange, Act, Assert.
  4. Run all tests in the IDE; fix or plant a bug and show a test catching it.

Acceptance: at least 20 meaningful tests; one bug found or a planted bug caught.

Exercises (assessment: write tests for a provided class with hidden bugs; score = bugs caught)

IDOutcomeTask
BEG-045-EX011Give three reasons automated tests beat checking by hand, and say what a regression is.
BEG-045-EX021The test void t() { new Account(10).deposit(5); } has a problem. Name it and fix it.
BEG-045-EX032Write a JUnit 5 test for int max(int a, int b) with two cases.
BEG-045-EX042Write a test proving Account.withdraw(-1) throws IllegalArgumentException.
BEG-045-EX053A method isAdult(int age) returns true from 18 up and rejects negative ages. List the equivalence classes and the boundary inputs.
BEG-045-EX064A test reports expected: <3> but was: <2> for list.size() after three adds. List the steps to find the cause.
أظهر الحلول
  • EX01 Faster, repeatable, catches regressions, documents behavior. A regression is a feature that worked and broke after a change.
  • EX02 It has no assertion, so it can never fail. Add assertEquals(15, account.getBalance()); after the deposit.
  • EX03 @Test void returnsLarger() { assertEquals(7, max(3, 7)); } @Test void handlesEqual() { assertEquals(4, max(4, 4)); }
  • EX04 assertThrows(IllegalArgumentException.class, () -> account.withdraw(-1));
  • EX05 Classes: negative (error), 0 to 17 (false), 18 and above (true). Boundaries: -1, 0, 17, 18, 19.
  • EX06 Read the message (code returned 2); click the failing line; check the three adds (one may be rejected, or add is not incrementing size); fix the code and rerun all tests.

الاختبار

Outcomes: O1 why test and test-case anatomy · O2 JUnit 5 · O3 boundaries and equivalence classes · O4 running tests and reading failures.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1A regression is:O1
  2. 2The three steps of a test are:O1
  3. 3A test with no assertion:O1
  4. 4The annotation that marks a JUnit 5 test method is:O2
  5. 5In assertEquals(a, b) the first argument should be the:O2
  6. 6To check that code throws IllegalArgumentException use:O2
  7. 7A boundary test for "age must be at least 18" should include:O3
  8. 8An equivalence class is a group of inputs that:O3
  9. 9Which tests a method best?O3
  10. 10expected: <5> but was: <4> means the code returned:O4

الجزء العملي

Write tests for a provided class with hidden bugs (score = bugs caught) plus lab BEG-045-LAB1 (at least 20 meaningful tests) and exercises BEG-045-EX01 to EX06. Pass: at least half of the hidden bugs caught, the lab acceptance met, and at least 8 of 10 quiz answers correct.

أخطاء شائعة

Tests with no assertions; testing only the happy path; tests that depend on each other.

التقييم

Write tests for a provided class with hidden bugs; score = bugs caught.

الصلة بالمسار الوظيفي

JNR-043 to JNR-047 and quality engineering throughout.

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