# คู่มือการปฏิบัติงานโครงงาน - ขั้นตอนปฏิบัติจริง

---

## ตัวเลือกที่ 1: Complete Testing Audit

### สัปดาห์ที่ 1: Phase Planning and Static Testing

#### งาน 1.1: เขียน Test Plan (2-3 วัน)
สอบเป็นผู้รับผิดชอบ: Test Lead

เอกสารควรประกอบด้วย:
1. Executive Summary
2. Scope (ระบบ Library Management System)
3. Objectives (7 Learning Objectives)
4. Test Strategy (Black Box, White Box, Security)
5. Risk Assessment (5-7 risks)
6. Entry/Exit Criteria
7. Resource Planning (บทบาทคนต่างคน)
8. Schedule (3 weeks)
9. Test Environment Requirements

อ้างอิง:
- สัปดาห์ที่ 3: Test Planning and Strategy (wk03-1-th.md)
- ใช้ ISO 25010 attributes เป็นมิติการทดสอบ

ผลผลิต:
- Test Plan Document (5-7 pages)
- Risk Register (High/Medium/Low)

---

#### งาน 1.2: Code Review and Static Analysis (2-3 วัน)
สอบเป็นผู้รับผิดชอบ: Code Reviewer

ขั้นตอน:
1. Setup ESLint and Prettier
   ```bash
   cd Library-Management
   npm install --save-dev eslint prettier
   npx eslint --init
   ```

2. Run Analysis
   ```bash
   npx eslint src/**/*.js --format json > eslint-report.json
   npx prettier --write src/**/*.js
   ```

3. Manual Code Review using Checklist
   - ชื่อตัวแปร (camelCase, clarity)
   - ความยาวของฟังก์ชัน (ideal < 20 lines)
   - ความเห็นและเอกสารประกอบ
   - Error Handling (try-catch)
   - ความเสี่ยงด้านความปลอดภัย (SQL Injection ready code)

อ้างอิง: สัปดาห์ที่ 6: Static Testing (wk06-th-1.md, wk06-th-2-v2.md)

ผลผลิต:
- ESLint Report (JSON and HTML)
- Code Review Checklist Completed
- Inspection Report (5 pages)

---

#### งาน 1.3: Design Black Box Test Cases (3-4 วัน)
สอบเป็นผู้รับผิดชอบ: Test Designer

วิธีการ:
1. Equivalence Partitioning (EP)
   - แบ่ง inputs into valid/invalid partitions
   - ตัวอย่าง: Username field - Valid, Empty, Too Long, Special Chars

2. Boundary Value Analysis (BVA)
   - ทดสอบที่ขอบเขต: min, min+1, max-1, max
   - ตัวอย่าง: Book ID - 0, 1, 999999, 1000000

3. Decision Table Testing
   - สำหรับ complex business logic
   - ตัวอย่าง: Book Borrowing (Available, Overdue, Reserved)

4. State Transition Testing
   - Book Status: Available to Borrowed to Returned

รูปแบบ Test Cases:
```
Test Case ID: TC-001
ชื่อ: Successful Book Search
Precondition: User is logged in
ขั้นตอน:
  1. Navigate to Search page
  2. Enter book title "Harry Potter"
  3. Click Search button
ผลลัพธ์ที่คาดหวัง: Display search results
Priority: High
```

เครื่องมือ:
- Excel or Google Sheets (สำหรับเอกสาร)
- หรือ TestLink ถ้ามี

เป้าหมาย: 60+ test cases

อ้างอิง:
- สัปดาห์ที่ 4: Test Case Design (wk04_th-lec.md)
- สัปดาห์ที่ 5: Black Box Testing (wk05-th-2-v2.md)

ผลผลิต:
- Test Case Document (Excel/PDF)
- Test Case Summary (10-15 pages)

---

### สัปดาห์ที่ 2: Execution and Unit Testing

#### งาน 2.1: Execute Black Box Tests (3-4 วัน)
สอบเป็นผู้รับผิดชอบ: Black Box Tester

กระบวนการ:
1. ตามดำเนินการ test cases ทีละอัน
2. เอกสารประกอบผลลัพธ์:
   - Pass
   - Fail (with screenshot)
   - Inconclusive
3. สำหรับ failed cases - สร้าง Bug Report

รูปแบบ Bug Report:
```
Bug ID: BUG-001
ชื่อ: Login button not responding
Severity: High
Priority: High
ขั้นตอนการทำซ้ำ:
  1. Click Login button
  2. Enter credentials
  3. Click Submit
คาดหวัง: Login page
จริง: No response
Attachment: Screenshot
```

เป้าหมาย: 15-25 bugs

ผลผลิต:
- Test Execution Log (ทั้งหมด 60+ cases)
- Bug Reports (15-25 bugs)
- Test Summary Report (Pass/Fail percentage)

---

#### งาน 2.2: Unit Testing with Jest (2-3 วัน)
สอบเป็นผู้รับผิดชอบ: White Box Tester

ขั้นตอน:
1. ระบุฟังก์ชันที่จะทดสอบ (5-10 functions)
2. เขียน Jest tests
   ```javascript
   describe('Book Search', () => {
     test('should find book by title', () => {
       const results = searchBooks('Harry');
       expect(results.length).toBeGreaterThan(0);
     });

     test('should return empty when not found', () => {
       const results = searchBooks('NonExistent');
       expect(results).toEqual([]);
     });
   });
   ```

3. Run coverage report
   ```bash
   npm test -- --coverage
   ```

เป้าหมาย:
- 15-20 unit tests
- พยายามหา 70% ขึ้นไป code coverage

อ้างอิง: สัปดาห์ที่ 7: White Box Testing and Unit Testing (wk07-th-1.md, wk07-th-2-v2.md)

ผลผลิต:
- Jest test files (.test.js)
- Coverage Report (HTML)

---

### สัปดาห์ที่ 3: Integration, Security and Final Report

#### งาน 3.1: Integration Testing (2 วัน)
สอบเป็นผู้รับผิดชอบ: Integration Tester

เน้นไปที่ API endpoints:
```javascript
const request = require('supertest');
const app = require('../app');

describe('Book API', () => {
  test('GET /api/books should return list', async () => {
    const res = await request(app).get('/api/books');
    expect(res.status).toBe(200);
    expect(Array.isArray(res.body)).toBe(true);
  });
});
```

เป้าหมาย: 10-15 integration tests

อ้างอิง: สัปดาห์ที่ 9: Integration Testing (Week09_Integration_Testing.md)

ผลผลิต:
- Integration test code
- Test execution report

---

#### งาน 3.2: Security Testing (2-3 วัน)
สอบเป็นผู้รับผิดชอบ: Security Tester

ทดสอบสำหรับ:
1. SQL Injection (4 methods)
   - ตัวอย่าง: Login field - ' OR '1'='1

2. XSS (Cross-Site Scripting)
   - ตัวอย่าง: Search field - <script>alert('XSS')</script>

3. Authentication and Session
   - ทดสอบ session timeout
   - ทดสอบ logout effectiveness

เครื่องมือ:
- Burp Suite Community (free)
- Browser Dev Tools

อ้างอิง: สัปดาห์ที่ 12: Security Testing (Week12_Lecture_Security_Testing.md)

ผลผลิต:
- Security Test Report (10-15 pages)
- Vulnerability List (with risk rating)

---

#### งาน 3.3: Compile Final Report (2-3 วัน)
สอบเป็นผู้รับผิดชอบ: QA Analyst and All

โครงสร้าง:
```
1. Executive Summary (2 pages)
2. Test Plan and Strategy (5 pages)
3. Test Cases Summary (10 pages)
4. Test Results (Pass/Fail Analysis)
5. Bug Reports (Grouped by Category)
6. Code Quality Analysis (5 pages)
7. Security Assessment (5 pages)
8. Quality Metrics (5 pages)
   - Defect Density
   - Test Coverage
   - DRE (Defect Removal Efficiency)
9. Recommendations (3-5 pages)
10. Appendices (Test logs, screenshots)
```

รวม: 15-20 pages

ผลผลิต:
- Final Report (PDF)
- Presentation Slides (10 slides)

---

## ตัวเลือกที่ 2: API and Integration Testing Focus

### Phase 1: API Audit and Test Design (สัปดาห์ที่ 1)

#### งาน 1.1: API Documentation Review (1 วัน)
ทบทวน API endpoints ทั้งหมด:
```
GET    /api/books         - List all books
GET    /api/books/:id     - Get book by ID
POST   /api/books         - Create new book
PUT    /api/books/:id     - Update book
DELETE /api/books/:id     - Delete book
GET    /api/auth/login    - Login
POST   /api/borrow        - Borrow book
```

#### งาน 1.2: Design API Test Cases (2-3 วัน)
สำหรับแต่ละ endpoint:
- Happy path (valid data)
- Sad path (invalid data)
- Edge cases (boundary values)
- Error handling

เป้าหมาย: 40+ test cases

#### งาน 1.3: Contract Testing (1 วัน)
กำหนด JSON Schema สำหรับ responses:
```json
{
  "type": "object",
  "properties": {
    "id": { "type": "number" },
    "title": { "type": "string" },
    "author": { "type": "string" }
  }
}
```

### Phase 2: Implementation (สัปดาห์ที่ 2-3)

#### งาน 2.1: Unit Tests (5-7 วัน)
- ทดสอบ business logic functions

#### งาน 2.2: Integration Tests (3-4 วัน)
- ทดสอบกับ actual database
- ทดสอบ error responses

#### งาน 2.3: Security Testing (2-3 วัน)
- API Authorization
- Input validation
- Rate limiting

---

## ตัวเลือกที่ 3: User Experience and End-to-End Testing

### Phase 1: User Journey and Exploratory Testing (สัปดาห์ที่ 1)

#### งาน 1.1: User Journey Mapping (1-2 วัน)
ตัวอย่าง: Book Borrowing User Journey
```
1. User logs in
2. Searches for book
3. Views book details
4. Clicks "Borrow"
5. Confirms borrowing
6. Views borrowed books list
7. Logs out
```

#### งาน 1.2: Exploratory Testing (2 วัน)
- ใช้ Session-Based Testing (SBTM)
- เอกสารประกอบ findings

#### งาน 1.3: Design End-to-End Test Cases (1-2 วัน)
- One test per user journey
- เป้าหมาย: 40+ scenarios

### Phase 2: Automation (สัปดาห์ที่ 2-3)

#### งาน 2.1: Playwright Setup (1 วัน)
```bash
npm install -D @playwright/test
npx playwright install
```

#### งาน 2.2: Page Object Model (POM) (2-3 วัน)
```javascript
class LoginPage {
  async login(username, password) {
    await page.fill('[data-testid="username"]', username);
    await page.fill('[data-testid="password"]', password);
    await page.click('[data-testid="login-btn"]');
  }
}
```

#### งาน 2.3: Write Tests (3-5 วัน)
- 30-40 Playwright tests
- Cross-browser testing

#### งาน 2.4: Visual Regression (2-3 วัน)
- Screenshot comparison
- Responsive design testing

---

## ตัวเลือกที่ 4: Security and Code Quality

### Phase 1: Static Analysis (สัปดาห์ที่ 1)

#### งาน 1.1: Code Review (2-3 วัน)
- ใช้ ESLint
- Manual inspection
- Security checklist

#### งาน 1.2: Design Unit Tests (2 วัน)
- เน้น security-sensitive functions
- เป้าหมาย: 20+ tests with high coverage

### Phase 2: Security Testing (สัปดาห์ที่ 2-3)

#### งาน 2.1: Security Test Plan (1 วัน)
#### งาน 2.2: Manual Security Testing (3-4 วัน)
- SQL Injection tests
- XSS tests
- Authentication tests

#### งาน 2.3: Code Coverage Analysis (2 วัน)
- บรรลุ 70%+ coverage
- เอกสารประกอบ coverage report

#### งาน 2.4: Final Report (2 วัน)
- Security findings
- Code quality metrics
- Recommendations

---

## ผลผลิตร่วม (ทั้งหมด)

### GitHub Repository Setup
```
library-testing/
├── test-cases/
│   └── test-cases.xlsx
├── bug-reports/
│   └── bugs.md
├── test-results/
│   └── results.json
├── src/
│   └── (source code or copy)
├── tests/
│   ├── unit/
│   ├── integration/
│   └── e2e/
├── reports/
│   └── final-report.pdf
└── README.md
```

### GitHub Issues
- สร้าง issue สำหรับแต่ละ bug ที่พบ
- Label by severity, component, etc.
- Assign team member responsible

### Test Report Metrics (ทั้งหมด)
```
Total Tests Planned: 60+
Total Tests Executed: 60+
Tests Passed: XX
Tests Failed: XX
Test Coverage: XX%
Bugs Found: XX
Critical: XX
High: XX
Medium: XX
Low: XX
```

---

## Presentation Checklist (ทั้งหมด)

- 10 นาทีพอดี
- ชื่อโครงงานชัดเจน
- บทบาทสมาชิกกลุ่มแสดงให้เห็น
- วิธีการทดสอบอธิบายชัดเจน
- Live demo (ถ้าเป็นไปได้)
- Key findings highlighted
- Metrics and data visualized
- Q and A section 5 minutes

---

## อ้างอิงตามสัปดาห์

| สัปดาห์ | หัวข้อ | ไฟล์ |
|--------|--------|------|
| 1 | Testing Introduction | wk01-th-lec.md |
| 2 | Quality Metrics | Week02_Lecture_Software_Quality_and_Metrics-th.md |
| 3 | Test Planning | wk03-1-th.md, wk03-2-th.md |
| 4 | Test Case Design | wk04_th-lec.md |
| 5 | Black Box Testing | wk05-th-1.md, wk05-th-2-v2.md |
| 6 | Static Testing | wk06-th-1.md, wk06-th-2-v2.md |
| 7 | Unit Testing | wk07-th-1.md, wk07-th-2-v2.md |
| 9 | Integration Testing | Week09_Integration_Testing.md |
| 10 | End-to-End Testing | wk10-lab.md |
| 11 | Test Automation | wk11-th-lab.md |
| 12 | Security Testing | Week12_Lecture_Security_Testing.md |

---

สร้างเมื่อ: 16 มีนาคม 2026
วิทวัส พันธุมจินดา
