๐Ÿงช Lecture 16 ยท Quality assurance & testing

Software Testing, TDD & APIs

ุงู…ุชุญุงู† ุงู„ุดุชุง ุจุชุงุน 2025 ุฌุงุจ 4 ุฃุณุฆู„ุฉ ู…ู† ู‡ู†ุง: TDD steps, REST APIs, Black-box, White-box. ู„ุงุฒู… ุชุนุฑู ุงู„ู€ TDD cycle ูˆุงู„ู€ HTTP methods ูƒูˆูŠุณ ุฌุฏุงู‹.

7
Chapters
5
Rules of Bugs
3
TDD Laws
8
Exam Qs
01

Introduction to Testing

"Program testing can show the presence of bugs, but never their absence" โ€” Dijkstra.

๐Ÿ“– Definitions
  • Software Testing = ุฅู†ูƒ ุชุดุบู„ ุงู„ุจุฑู†ุงู…ุฌ ุจุบุฑุถ ุฅู†ูƒ ุชู„ุงู‚ูŠ ุงู„ู€ errors ุงู„ู„ูŠ ููŠู‡.
  • ู‡ูŠ ุนู…ู„ูŠุฉ ุจุชุฏูŠูƒ ุซู‚ุฉ ุฅู† ุงู„ุจุฑู†ุงู…ุฌ ุจูŠุนู…ู„ ุงู„ู…ุทู„ูˆุจ ู…ู†ู‡ ุจุงู„ุธุจุท ุนู† ุทุฑูŠู‚ ุฅู†ูƒ ุชุฌุฑุจู‡ ุนู„ู‰ ุฏุงุชุง ู…ุฎุชู„ูุฉ (test data).
  • ู†ุดุงุท ุฎุงุต ุจุงู„ู€ QA ู‡ุฏูู‡ ุฅู†ู‡ ูŠู„ุงู‚ูŠ ุงู„ู€ bugs ููŠ ุงู„ูƒูˆุฏ ุงู„ุดุบุงู„ ูˆูŠุตู„ุญู‡ุง.
๐Ÿ‘ฅ Tester vs QA Engineer
  • Tester: ู‡ูˆ ุงู„ู„ูŠ ุจูŠูƒุชุจ ุงู„ู€ test cases ูˆูŠุดุบู„ ุงู„ุจุฑู†ุงู…ุฌ ุนุดุงู† ูŠู„ุงู‚ูŠ ุงู„ู€ bugs.
  • QA Engineer: ู‡ูˆ ุงู„ู„ูŠ ุจูŠุฎุทุท ู„ู„ู€ QA ูˆุจูŠุญุท standards ูˆุทุฑู‚ ุนุดุงู† ูŠู…ู†ุน ุงู„ู€ bugs ุฅู†ู‡ุง ุชุญุตู„ ู…ู† ุงู„ุฃุณุงุณ.
๐Ÿ’ก Lion King 1994 DisasterุฏูŠุฒู†ูŠ ู†ุฒู„ุช ู„ุนุจุฉ "Lion King Animated Storybook" ุนู„ู‰ CD-ROM ู…ู† ุบูŠุฑ ู…ุง ุชุนู…ู„ู‡ุง testing ุนู„ู‰ ู…ูˆุฏูŠู„ุงุช PC ู…ุฎุชู„ูุฉ. ุจุนุฏ ุงู„ูƒุฑูŠุณู…ุงุณ ููŠ 1995ุŒ ุงู„ุชู„ูŠููˆู†ุงุช ู…ุงุจุทู„ุชุด ุฑู† ู…ู† ุงู„ุฃู‡ุงู„ูŠ ุงู„ุบุถุจุงู†ุฉ. ุฏูŠุฒู†ูŠ ุงุถุทุฑุช ุชุนูŠู† ูุฑูŠู‚ ุฏุนู… ูู†ูŠุŒ ูˆุชุนู…ู„ debug cycle ุชุงู†ูŠุฉุŒ ูˆุชุดุญู† ุขู„ุงู ุงู„ู€ CDs ุงู„ุจุฏูŠู„ุฉ ู„ู„ู†ุงุณ.
02

Bugs โ€” Cost & Types

Cost of bug grows exponentially as it's found later.

๐Ÿ’ฐ The Cost of Bugs (Ron Patton)
Phase Cost to Fix
Specification $1
Design $10
Code $100
Test $1,000
Release $1,000+

Goal: ุชู„ุงู‚ูŠ ุงู„ู€ bugs ุจุฏุฑูŠ ุนู„ู‰ ู‚ุฏ ู…ุง ุชู‚ุฏุฑ (ุนุดุงู† ุงู„ุชูƒู„ูุฉ ู…ุชุฒูŠุฏุด).

๐Ÿ“œ 5 Rules That Define a Bug

ุงู…ุชู‰ ู†ู‚ูˆู„ ุฅู† ููŠู‡ bugุŸ ู„ูˆ ุญุตู„ ุญุงุฌุฉ ุฃูˆ ุฃูƒุชุฑ ู…ู† ุฏูˆู„:

  1. Rule 1: ุงู„ุณูˆูุชูˆูŠุฑ ู…ุจูŠุนู…ู„ุด ุญุงุฌุฉ ุงู„ู€ spec ู‚ุงู„ ุฅู†ู‡ ุงู„ู…ูุฑูˆุถ ูŠุนู…ู„ู‡ุง.
  2. Rule 2: ุงู„ุณูˆูุชูˆูŠุฑ ุจูŠุนู…ู„ ุญุงุฌุฉ ุงู„ู€ spec ู‚ุงู„ ุฅู†ู‡ ุงู„ู…ูุฑูˆุถ ู…ูŠุนู…ู„ู‡ุงุด.
  3. Rule 3: ุงู„ุณูˆูุชูˆูŠุฑ ุจูŠุนู…ู„ ุญุงุฌุฉ ุงู„ู€ spec ู…ุฌุงุจุด ุณูŠุฑุชู‡ุง ุฎุงู„ุต.
  4. Rule 4: ุงู„ุณูˆูุชูˆูŠุฑ ู…ุจูŠุนู…ู„ุด ุญุงุฌุฉ ุงู„ู€ spec ู…ุฌุงุจุด ุณูŠุฑุชู‡ุง ุจุณ ุงู„ู…ูุฑูˆุถ ุจุฏูŠู‡ูŠุงู‹ ุชุชุนู…ู„.
  5. Rule 5: ุงู„ุณูˆูุชูˆูŠุฑ ุตุนุจ ูŠุชูู‡ู…ุŒ ุฑุฎู… ููŠ ุงุณุชุฎุฏุงู…ู‡ุŒ ุฃูˆ ุจุทูŠุก... ูŠุนู†ูŠ ู…ุด ู…ุธุจูˆุท.
๐Ÿšจ Severity (How Bad)
1
Critical
System crashes, security breach
2
Major
Wrong result, loss of functionality
3
Minor
Misspelling, UI layout, rare occurrence
4
Suggestion
Improvement idea
โฐ Priority (How Soon)
  1. Immediate fix โ€” ู„ุงุฒู… ุชุชุตู„ุญ ููˆุฑุงู‹ ู„ุฃู†ู‡ุง ุจุชุนุทู„ ุงู„ู€ testing ูˆูˆุงุถุญุฉ ุฌุฏุงู‹.
  2. ู„ุงุฒู… ุชุชุตู„ุญ ู‚ุจู„ ุงู„ู€ release.
  3. ูŠุณุชุญุณู† ุชุชุตู„ุญ ู„ู…ุง ูŠูƒูˆู† ููŠู‡ ูˆู‚ุช.
  4. ูŠุง ุฑูŠุช ุชุชุตู„ุญ ุจุณ ูŠู†ูุน ู†ู†ุฒู„ ุจุงู„ู€ release ุนุงุฏูŠ ู…ู† ุบูŠุฑู‡ุง.
๐Ÿ’ก Sev vs Priุงู„ู€ Severity (ุงู„ุดุฏุฉ) = ุชุฃุซูŠุฑู‡ุง ุนุงู…ู„ ุฅุฒุงูŠ. ุงู„ู€ Priority (ุงู„ุฃูˆู„ูˆูŠุฉ) = ุงู„ุณุฑุนุฉ ุงู„ู„ูŠ ู…ุญุชุงุฌูŠู† ู†ุตู„ุญู‡ุง ุจูŠู‡ุง. ู…ุซู„ุงู‹: ุบู„ุทุฉ ุฅู…ู„ุงุฆูŠุฉ (Misspelling) ุฎู„ุช ุขู„ุงู ุงู„ูŠูˆุฒุฑุฒ ูŠุชุตู„ูˆุง ุจุงู„ุฏุนู… ุงู„ูู†ูŠ = ุฏูŠ Severity 3 ุจุณ Priority 2 (ู„ุฃู†ู‡ุง ู…ุด ู‚ุงุชู„ุฉ ุจุณ ู„ุงุฒู… ุชุชุตู„ุญ ุจุณุฑุนุฉ ุนุดุงู† ูˆุฌุน ุงู„ุฏู…ุงุบ).
03

Testing Levels (Stages)

4 ู…ุณุชูˆูŠุงุช ุจุชุจุฏุฃ ู…ู† ุงู„ู€ unit ู„ุญุฏ ุงู„ู€ acceptance.

๐Ÿ“Š 4 Levels (Bottom-Up)
Acceptance Testing โ€” System ready for delivery?
System Testing โ€” Whole system vs requirements
Integration Testing โ€” Combined units interactions
Unit Testing โ€” Individual components
Level Purpose
Unit (UT) Test individual components; each unit performs as designed
Integration (IT) Test groups of units to expose interaction faults
System (ST) Complete integrated system vs specified requirements
Acceptance (AT) Business requirements + delivery readiness
04

Black-Box vs White-Box

ุฎุฏ ุจุงู„ูƒุŒ ุงู…ุชุญุงู† ุงู„ุดุชุง ุจุชุงุน 2025 ุณุฃู„ ุนู† ุงู„ู€ Black-box equivalence partitioning.

โฌ› Black-Box (Specification-based)
  • ุจูŠุชุฃูƒุฏ ุฅู† ุงู„ุจุฑู†ุงู…ุฌ ู…ุงุดูŠ ู…ุน ุงู„ู€ specification ุงู„ู…ูƒุชูˆุจุฉ โ†’ (function coverage).
  • Abstraction from details: ู…ุด ู…ุญุชุงุฌ ุชุดูˆู ุงู„ู€ source code ุฃุตู„ุงู‹.
  • Scales up: ุจูŠู†ูุน ู…ุน ูƒู„ ุงู„ู…ุณุชูˆูŠุงุช (unit, integration, system, acceptance).
  • ุจูŠูƒุดู ุงู„ู€ missing functionality (ุงู„ุญุงุฌุงุช ุงู„ู„ูŠ ู†ุงู‚ุตุฉ ูˆู…ุด ู…ูˆุฌูˆุฏุฉุŒ ูˆุฏู‡ ุงู„ู€ white-box ู…ูŠุนุฑูุด ูŠุนู…ู„ู‡).
  • ู…ู† ุทุฑู‚ู‡: Equivalence Partitioning ูˆุงู„ู€ Boundary Value Analysis.
โฌœ White-Box (Structural)
  • ุจูŠุชูŠุณุช ุนู„ู‰ ุงู„ู€ implementation ู†ูุณู‡ (ุงู„ูƒูˆุฏ).
  • ุงู„ู€ tester ุจูŠูƒูˆู† ู…ุชุฃูƒุฏ ู…ู† ุงู„ู€ code coverage (ุบุทู‰ ูƒุงู… ุณุทุฑ).
  • ู…ุจู†ูŠ ุนู„ู‰ ู…ุณุงุฑ ุงู„ุฏุงุชุง ูˆุงู„ูƒู†ุชุฑูˆู„ ููŠ ุงู„ูƒูˆุฏ โ€” ูุจูŠุณู‡ู‘ู„ ุงู„ู€ debugging.
  • ู…ุจูŠู†ูุนุด ูŠูƒุจุฑ ู…ุนุงูƒ ุฃูˆูŠ (Does NOT scale up) โ€” ุจูŠููŠุฏ ุฃูƒุชุฑ ุญุงุฌุฉ ููŠ ุงู„ู€ unit ูˆุงู„ู€ integration.
  • ุฃู†ูˆุงุน ุงู„ู€ Coverage ููŠู‡: Statement, Branch, Path.
  • ุจูŠูƒุดู ุงู„ู€ unexpected functionality (ุงู„ุญุงุฌุงุช ุงู„ู„ูŠ ุงู„ูƒูˆุฏ ุจูŠุนู…ู„ู‡ุง ุจุงู„ุบู„ุท ุฃูˆ ุฒูŠุงุฏุฉ).
๐Ÿ’ก ู†ุตูŠุญุฉุงุณุชุฎุฏู… ุงู„ุงุชู†ูŠู† ู…ุน ุจุนุถ! ูƒู„ ูˆุงุญุฏ ููŠู‡ู… ุจูŠูƒุดู ุฃู†ูˆุงุน ู…ุฎุชู„ูุฉ ู…ู† ุงู„ู€ bugs.
๐Ÿ“Š Equivalence Partitioning (BB)

ุจุชู‚ุณู… ุงู„ู€ inputs ุงู„ู„ูŠ ุนู†ุฏูƒ ู„ู€ ู…ุฌู…ูˆุนุชูŠู† ุฃูˆ ุฃูƒุชุฑ:

  • ู…ุฌู…ูˆุนุฉ ุงู„ู€ Valid (ุงู„ุตุญ ุงู„ู„ูŠ ุงู„ู…ูุฑูˆุถ ูŠุชู‚ุจู„)
  • ู…ุฌู…ูˆุนุฉ ุงู„ู€ Invalid (ุงู„ุบู„ุท ุงู„ู„ูŠ ุงู„ู…ูุฑูˆุถ ูŠุชุฑูุถ)

ูˆุจุนุฏูŠู† ุชุงุฎุฏ ู‚ูŠู…ุฉ ูˆุงุญุฏุฉ ู…ู† ูƒู„ ู…ุฌู…ูˆุนุฉ ุชุฌุฑุจ ุจูŠู‡ุง (ูƒู€ ู…ู†ุฏูˆุจ ุนู† ุงู„ุจุงู‚ูŠ).

Example โ€” Reward Points (Winter 2025 Q1.04)

Function returns reward points. If purchase โ‰ค 1000 LE โ†’ 10%. If > 1000 LE โ†’ 20%. If input is negative โ†’ throw exception.

Partitions:

  • Input โ‰ค 0 โ†’ exception
  • Input (0, 1000] โ†’ 10% reward
  • Input > 1000 โ†’ 20% reward

Test cases to cover all partitions:

TC1: input 100,  output 10     (10% partition)
TC2: input 1000, output 100    (10% partition โ€” boundary)
TC3: input -100, throw exception (invalid)
// But this misses the 20% partition!

// Correct set:
TC1: 10 & M, 18 & F, 75 & F     // (Winter 2025 example)
TC2: 100 โ†’ 10,  2000 โ†’ 400,  -200 โ†’ throw
๐ŸŽฏ Boundary Value Analysis

ุฃุบู„ุจ ุงู„ู€ bugs ุจุชุจู‚ู‰ ู…ูˆุฌูˆุฏุฉ ุนู†ุฏ ุงู„ู€ boundaries (ุงู„ุญุฏูˆุฏ). ุนุดุงู† ูƒุฏู‡ ุฌุฑุจ ู‚ูŠู…ุฉ ุนู„ู‰ ุงู„ุญุฏ ุจุงู„ุธุจุทุŒ ูˆุฃู‚ู„ ู…ู†ู‡ ุจุณู†ุฉุŒ ูˆุฃูƒุจุฑ ู…ู†ู‡ ุจุณู†ุฉ.

ู…ุซุงู„ ู„ูˆ ุงู„ุนู…ุฑ ู…ู† 18 ู„ู€ 65:

  • 17, 18, 19 (ุงู„ุญุฏ ุงู„ู„ูŠ ุชุญุช)
  • 64, 65, 66 (ุงู„ุญุฏ ุงู„ู„ูŠ ููˆู‚)
  • -1, 0, 1 (ุญุงู„ุงุช ุฎุงุตุฉ ุนู†ุฏ ุงู„ุตูุฑ)
05

Test-Driven Development (TDD) โญ

ุฌู‡ ููŠ ุงู…ุชุญุงู† ุงู„ุดุชุง ุจุชุงุน 2025 ุณุคุงู„ ุนู† ุชุฑุชูŠุจ ุงู„ู€ TDD steps.

๐Ÿ”„ TDD Definition

ุงู„ู€ TDD ู‡ูˆ ุฃุณู„ูˆุจ ููŠ ุงู„ุดุบู„ ุจู†ุฑูƒุฒ ููŠู‡ ุฅู†ู†ุง ู†ูƒุชุจ ุงู„ู€ unit test cases ุงู„ุฃูˆู„ ู‚ุจู„ ู…ุง ู†ูƒุชุจ ูƒูˆุฏ ุงู„ุจุฑู†ุงู…ุฌ ู†ูุณู‡.

ุดุบุงู„ูŠู† ุจู†ุธุงู… iterative (ู„ูุงุช) ุจุชุฌู…ุน ุจูŠู†: ูƒุชุงุจุฉ ุงู„ูƒูˆุฏ + ุงู„ู€ unit tests + ุชุธุจูŠุท ุงู„ูƒูˆุฏ (refactoring).

๐Ÿ”ด๐ŸŸข๐Ÿ”ต The TDD Cycle
๐Ÿ”ด
1. RED
ุงูƒุชุจ ุชุณุช ุจูŠููŠู„
โ†’
๐ŸŸข
2. GREEN
ุงูƒุชุจ ูƒูˆุฏ ูŠู…ุดู‘ูŠ ุงู„ุชุณุช
โ†’
๐Ÿ”ต
3. REFACTOR
ู†ุถู‘ู ุงู„ูƒูˆุฏ ู…ู† ุบูŠุฑ ู…ุง ุชูƒุณุฑู‡
๐Ÿ“œ 3 Laws of TDD (Uncle Bob)
  1. ู…ู…ู†ูˆุน ุชูƒุชุจ ุฃูŠ production code ู‚ุจู„ ู…ุง ุชูƒุชุจ ุชุณุช ุจูŠููŠู„ (failing test).
  2. ู…ู…ู†ูˆุน ุชูƒุชุจ ูƒูˆุฏ ููŠ ุงู„ุชุณุช ุฃูƒุชุฑ ู…ู† ุงู„ู„ูŠ ู…ุญุชุงุฌู‡ ุนุดุงู† ูŠููŠู„.
  3. ู…ู…ู†ูˆุน ุชูƒุชุจ production code ุฃูƒุชุฑ ู…ู† ุงู„ู„ูŠ ู…ุญุชุงุฌู‡ ุนุดุงู† ุชู†ุฌุญ ุงู„ุชุณุช ุงู„ู„ูŠ ุจูŠููŠู„ ุฏู„ูˆู‚ุชูŠ.
๐Ÿ“‹ Step Order โญ (Winter 2025 Q1.01)

ุชุฑุชูŠุจ ุฎุทูˆุงุช ุงู„ู€ TDD ุงู„ุตุญ ูƒุงู„ุชุงู„ูŠ (ุฏู‡ ุณุคุงู„ ุฌู‡ ููŠ ุงู…ุชุญุงู† ุงู„ุดุชุง):

  1. ุงูƒุชุจ ุชุณุช (Write a test) (ุฎุทูˆุฉ 2 ููŠ ูˆุฑู‚ุฉ ุงู„ุฃุณุฆู„ุฉ)
  2. ุงู„ุชุณุช ูŠููŠู„ (Test fails) (ุฎุทูˆุฉ 3)
  3. ุงูƒุชุจ ุงู„ูƒูˆุฏ (Write code) (ุฎุทูˆุฉ 5)
  4. ุงู„ุชุณุช ูŠู†ุฌุญ (Test passes) (ุฎุทูˆุฉ 4)
  5. ู†ุถู ุงู„ูƒูˆุฏ (Refactor code) (ุฎุทูˆุฉ 1)
๐ŸŽฏ Answer: 2 โ†’ 3 โ†’ 5 โ†’ 4 โ†’ 1 = (c) in the exam.
๐Ÿ’ป Quick Example โ€” abs() function
JavaScript โ€” TDD cycle
// ๐Ÿ”ด Step 1: Write failing test
function testAbsoPos5() {
  return abso(5) === 5;
}

// ๐ŸŸข Step 2: Write minimal code
function abso(num) {
  return num;  // Just enough to pass
}

// ๐Ÿ”ด Step 3: Write new failing test
function testAbsoNeg5() {
  return abso(-5) === 5;
}

// ๐ŸŸข Step 4: Extend code to pass
function abso(num) {
  if (num < 0) return -num;
  return num;
}

// ๐Ÿ”ต Step 5: Refactor (if needed)
06

Python unittest Library

ุงู„ู€ standard library ููŠ ุจุงูŠุซูˆู† ุนุดุงู† ุชุนู…ู„ unit testing.

๐Ÿ unittest Anatomy
  1. ุจุชุนู…ู„ import unittest.
  2. ุชุนู…ู„ Import ู„ู„ูƒูˆุฏ ุจุชุงุนูƒ ุงู„ู„ูŠ ู‡ุชุนู…ู„ู‡ ุชุณุช: from my_module import my_function.
  3. ุชุนู…ู„ ูƒู„ุงุณ ู„ู„ุชุณุช: class TestMyCode(unittest.TestCase).
  4. ุชูƒุชุจ ุงู„ู€ test methods ุจุชุงุนุชูƒ ูˆู„ุงุฒู… ุชุจุฏุฃ ุจูƒู„ู…ุฉ test_.
import unittest
class TestSomething(unittest.TestCase):
    def test_pass(self):
        self.assertEqual(2 + 2, 4)
    def test_fail(self):
        self.assertEqual(2 + 2, 42)

if __name__ == '__main__':
    unittest.main()
โœ“ Common assert Methods
Method Use
assertEqual(a, b) Passes if a == b
assertNotEqual(a, b) Passes if a != b
assertTrue(x) Passes if x is truthy
assertFalse(x) Passes if x is falsy
assertIsNone(x) Passes if x is None
assertIsNotNone(x) Passes if x is not None
assertIn(a, list) Passes if a is in list
assertAlmostEqual(a, b) For floats (handles tiny diffs)
07

REST APIs โญ

Winter 2025 Q1.02: REST APIs โ€” which is FALSE?

๐Ÿ“ก What is a REST API?
  • API (Application Programming Interface) = set of rules to interact with another software.
  • REST (Representational State Transfer) = architectural style for web services serving data (not web pages).
  • Communicate over HTTP using standard methods.
  • Looks like a website BUT it's NOT a website. Has an endpoint.
  • Serves data, not web pages. Accessed by software.
๐ŸŒ HTTP Methods (CRUD)
GET
Read ยท retrieve data
POST
Create ยท new resource
PUT
Update existing
DELETE
Remove resource
Method Example
GET /users Fetches list of users
POST /users Adds a new user
PUT /users/1 Updates user with ID 1
DELETE /users/1 Deletes user with ID 1
๐Ÿ—๏ธ REST Architecture
  • Resources: objects/data the API manipulates (users, posts).
  • URIs (Uniform Resource Identifiers): unique endpoint per resource (/users/1).
  • HTTP Methods: GET, POST, PUT, DELETE.
  • Stateless: each request must contain ALL information needed โ€” no session state on server. โญ
  • Responses: status codes + data in JSON or XML.

HTTP Status Codes

Code Meaning
200 OK Successful GET
201 Created Successful POST
404 Not Found Resource doesn't exist
โš ๏ธ Winter 2025 Q1.02 โ€” FALSE statement"They maintain state/session information from one API call to the next" is FALSE. REST is STATELESS by design โ€” each request is independent.
๐Ÿ’ป Python REST Example
import requests

url = "https://catfact.ninja/fact"
try:
    response = requests.get(url)
    response.raise_for_status()  # Raise on HTTP error
    data = response.json()
    print(data)
except requests.exceptions.RequestException as e:
    print(f"Error: {e}")
๐ŸŽฏ

Exam Bank โ€” Lecture 16

4 ุฃุณุฆู„ุฉ ู…ู† Winter 2025 + 4 practice.

Question 1 Winter 2025 ยท Q1.01
Given these steps for TDD, what is the correct order?
1) refactor code ยท 2) write a test ยท 3) test fails ยท 4) test passes ยท 5) write code
A 5, 1, 3, 2, 4
B 5, 3, 1, 2, 4
C 2, 3, 5, 4, 1
D 2, 3, 1, 4, 5
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: C โ€” 2, 3, 5, 4, 1 ุชูƒุชุจ test (2) โ†’ ุงู„ู€ test ูŠูุดู„ (3) โ†’ ุชูƒุชุจ code (5) โ†’ ุงู„ู€ test ูŠู†ุฌุญ (4) โ†’ ุชุนู…ู„ refactor (1). ุฏูŠ ุงู„ู€ TDD cycle ุงู„ูƒู„ุงุณูŠูƒูŠุฉ ูŠุง ุฑูŠุณ.
Question 2 Winter 2025 ยท Q1.02
What is FALSE about REST APIs?
A They are designed as end points to access programs via other programs
B They maintain state/session information from one API call to the next
C They have a unique URI for each endpoint
D They can be implemented via HTTP requests returning JSON or XML
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: B ุงู„ู€ REST ุจุทุจูŠุนุชู‡ STATELESS. ูƒู„ request ู„ุงุฒู… ูŠูƒูˆู† ููŠู‡ ูƒู„ ุงู„ู…ุนู„ูˆู…ุงุช ุงู„ู…ุทู„ูˆุจุฉ. ุงู„ุณูŠุฑูุฑ ู…ุด ุจูŠุญูุธ ุฃูŠ session state.
Question 3 Winter 2025 ยท Q1.04
Function returns reward points: โ‰ค1000 LE โ†’ 10%, >1000 โ†’ 20%, negative โ†’ exception. Which test cases satisfy equivalence partitioning (covering all partitions)?
A TC1: 100โ†’10 ยท TC2: 1000โ†’100 ยท TC3: โˆ’100โ†’exception
B TC1: 0โ†’0 ยท TC2: 100โ†’10 ยท TC3: 1000โ†’100
C TC1: 1000โ†’100 ยท TC2: โˆ’200โ†’ex ยท TC3: โˆ’1000โ†’ex
D TC1: 200โ†’20 ยท TC2: 2000โ†’400 ยท TC3: โˆ’200โ†’exception
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: D โ€” All 3 partitions covered
  • 200 โ†’ 20 (ุฏูŠ ุจุชุบุทูŠ ุงู„ุฌุฒุก ุจุชุงุน ุงู„ู€ 10% ู„ู„ุฃุฑู‚ุงู… โ‰ค1000)
  • 2000 โ†’ 400 (ุฏูŠ ุจุชุบุทูŠ ุงู„ุฌุฒุก ุจุชุงุน ุงู„ู€ 20% ู„ู„ุฃุฑู‚ุงู… >1000)
  • โˆ’200 โ†’ exception (ุฏูŠ ุจุชุบุทูŠ ุงู„ุฌุฒุก ุงู„ู€ invalid)
A โ€” ุบุทุช ุงู„ู€ 10% ูˆุงู„ู€ invalid ุจุณุŒ ูˆู†ุณูŠุช ุงู„ู€ 20%. ยท B โ€” ู…ููŠุด ุญุงุฌุฉ ู„ู„ู€ invalid. ยท C โ€” ุฑู‚ู…ูŠู† ุจุงู„ุณุงู„ุจ (ู†ูุณ ุงู„ู€ partition)ุŒ ูˆู…ููŠุด ุญุงุฌุฉ ู„ู„ู€ 20%.
Question 4 Winter 2025 ยท Q1.03
Min test cases for: (1) FULL statement coverage, (2) FULL path coverage (not branch)?
A 2 for statement, 4 for path
B 1 for statement, 2 for path
C 2 for statement, 2 for path
D 1 for statement, 4 for path
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: D ุงู„ู€ Statement coverage = ูƒุงููŠ 1 TC ุจุณ ุนุดุงู† ูŠุถุฑุจ ูƒู„ ุงู„ู€ statements. ุฅู†ู…ุง ุงู„ู€ Path coverage = ู…ุญุชุงุฌ 1 TC ู„ูƒู„ ู…ุณุงุฑ ู…ุณุชู‚ู„. ุฏู‡ ูุฑู‚ ูƒู„ุงุณูŠูƒูŠ ุจูŠุฌูŠ ูƒุชูŠุฑ.
Question 5 Practice โ€” bug rules
The software performs square roots but the spec doesn't mention this functionality. Is this a bug? Which rule?
A Not a bug
B Rule 1 (didn't do what spec says)
C Rule 2 (did what spec says it shouldn't)
D Rule 3 (did something spec doesn't mention)
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: D โ€” Rule 3 ุฅู†ูƒ ุชุถูŠู features ู…ุด ู…ุชูˆุซู‚ุฉ ุฏู‡ ูŠุนุชุจุฑ bug. ุงู„ู€ spec ู‡ูˆ ุงู„ุฃุณุงุณ ุงู„ู„ูŠ ุจุชู…ุดูŠ ุนู„ูŠู‡ โ€” ุฃูŠ ุญุงุฌุฉ ุฒูŠุงุฏุฉ ุจุชุนุชุจุฑ uncontrolled scope (ุญุงุฌุฉ ุจุฑู‡ ุงู„ุณูŠุทุฑุฉ).
Question 6 Practice โ€” HTTP methods
To update an existing user's profile, which HTTP method?
A GET
B PUT
C POST
D DELETE
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: B โ€” PUT ุงู„ู€ PUT ุจูŠุญุฏุซ resource ู…ูˆุฌูˆุฏ. ุงู„ู€ POST ุจูŠูƒุฑูŠุช ูˆุงุญุฏ ุฌุฏูŠุฏ. ุงู„ู€ GET ุจูŠู‚ุฑุฃ. ูˆุงู„ู€ DELETE ุจูŠู…ุณุญ.
Question 7 Practice โ€” testing levels
Which testing level checks the system against business requirements before delivery?
A Unit Testing
B Integration Testing
C Acceptance Testing
D System Testing
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: C โ€” Acceptance Testing ุงู„ู€ Acceptance Testing ู…ุนู†ุงู‡ "ุฎู„ุงุต ุฌุงู‡ุฒ ู„ู„ุชุณู„ูŠู…" โ†’ ูุจูŠุฎุชุจุฑูˆู‡ ุจู†ุงุกู‹ ุนู„ู‰ ุงู„ู€ business requirements. ุฃู…ุง ุงู„ู€ System Testing ูุฏู‡ ุนุดุงู† ูŠุชุฃูƒุฏูˆุง ุฅู†ู‡ ู…ุทุงุจู‚ ู„ู„ู€ (technical) requirements.
Question 8 Practice โ€” TDD law
According to Uncle Bob's TDD laws, you may NOT write production code unless:
A You have written a failing test
B You have approval from the manager
C You have refactored the existing code
D You have written documentation
โœ… ุงู„ุฅุฌุงุจุฉ ุงู„ุตุญ: A โ€” Failing test first ุฃูˆู„ ู‚ุงู†ูˆู† ููŠ ุงู„ู€ TDD: ู…ุชูƒุชุจุด ุฃูŠ production code ุฅู„ุง ู„ู…ุง ูŠูƒูˆู† ููŠู‡ test ู…ูƒุชูˆุจ ูˆุจูŠูุดู„.
๐Ÿ“‹

Cheat Sheet

๐Ÿ› 5 Bug Rules

Rule 1
Doesn't do what spec says
Rule 2
Does what spec says it shouldn't
Rule 3
Does something spec doesn't mention
Rule 4
Doesn't do something it should (implicit)
Rule 5
Hard to use / slow / unfriendly

๐Ÿ”„ TDD Cycle

RED
Write a failing test
GREEN
Write minimal code to pass
REFACTOR
Clean up code, tests still pass
Order
Test โ†’ Fail โ†’ Code โ†’ Pass โ†’ Refactor

๐Ÿ“Š Testing Levels

Unit (UT)
Individual components
Integration (IT)
Combined units
System (ST)
Whole system vs specified req
Acceptance (AT)
Business req + delivery readiness

โฌ›โฌœ Box Testing

Black-Box
Spec-based, no code access, scales up
BB Technique
Equivalence Partitioning + Boundary Value
White-Box
Code-based, structural
WB Coverage
Statement < Branch < Path

๐ŸŒ REST API

GET
Read
POST
Create
PUT
Update
DELETE
Remove
Stateless
โญ NO session on server
Response format
JSON or XML

๐Ÿ“œ 3 TDD Laws (Uncle Bob)

Law 1
No production code until failing test
Law 2
Test only enough to fail
Law 3
Production code only enough to pass