B15 · 測試(後端視角) 詳細 ROADMAP
計畫文件,不會被 Quartz 渲染。
回主 roadmap → backend/ROADMAP.md
章節目標
本章只放後端特有的測試議題——後端單元測試跟 Spring / FastAPI / Express 整合、Repository / DB 測試策略、contract testing、fixture / factory、效能測試(跟 B19 壓測互補)。
通用測試主題(測試金字塔、TDD/BDD/SDD、測試策略)屬於 testing/ / process/ 系列,本章只引用不重寫。
🌱 基本介紹
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 01 | 後端測試的獨特挑戰 | 01-backend-testing-challenges | 🌱 | DB 狀態、外部服務、非同步、時間依賴、多 process 協調 |
❓ 為什麼需要
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 02 | 為什麼只寫 unit test 不夠 | 02-why-unit-not-enough | 🌱 | 真實錯誤常在整合點(ORM / MQ / cache)、mock 多了假 coverage、integration test 的成本與 ROI |
| 03 | 為什麼 Contract Test 在微服務很重要 | 03-why-contract-test-for-micro | 🌱 | Service A 改 API → B 在 production 才發現;consumer-driven contract |
🕰️ 演進
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 04 | 後端測試演進 | 04-backend-testing-evolution | 🌱 | 只 unit → 加 integration → 加 contract → 加 property-based → AI-assisted 生成測試 |
🧠 知識型
F15-A 通用原則(引用)
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 05 | 測試金字塔 | ⛔️ process/02-testing-strategy | 🌿 | 跨系列 |
| 06 | TDD / BDD / SDD | ⛔️ process/14-tdd-bdd-sdd | 🌿 | 跨系列 |
| 07 | Contract Testing(Pact) | ⛔️ testing/05-api-contract-testing | 🌿 | 跨系列 |
F15-B 後端特定
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 08 | Unit Test 在後端 | 08-backend-unit-test | 🌱 | Mock DI container、Repository mock、business logic 純函式化 |
| 09 | Integration Test | 09-integration-test | 🌱 | 跑真 DB(testcontainers)、清 state、並行測試的坑 |
| 10 | API Test(E2E-lite) | 10-api-test | 🌱 | 只測 API,不碰 UI;pytest-httpx / supertest / REST Assured |
| 11 | Contract Test(Pact)深入 | 11-pact-deep | 🌱 | Consumer-driven、provider verification、CI 整合 |
| 12 | Property-based Test | 12-property-based | 🌱 | Hypothesis / fast-check / jqwik;測試不變量(invariants)而非 example |
| 13 | Mutation Testing | 13-mutation-testing | 🌱 | Stryker / PIT / mutmut;真正衡量 test 有沒有抓到 bug |
F15-C Fixture / Factory
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 14 | Fixture vs Factory | 14-fixture-vs-factory | 🌱 | factory_boy / FactoryBot / Faker / mockup;為什麼 factory 比 fixture 靈活 |
| 15 | Test Data Management | ⛔️ testing/08-test-data-management | 🌿 | 跨系列 |
| 16 | Seed Data 策略 | 16-seed-data | 🌱 | Dev / staging / test 環境的 seed 差異、版控、migration 整合 |
F15-D Mock / Stub / Double
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 17 | Test Double 分類 | 17-test-doubles | 🌱 | Dummy / Fake / Stub / Spy / Mock 語意區分 |
| 18 | Mock 外部服務 | 18-mock-external | 🌱 | WireMock / nock / httpx_mock / MockServer;什麼時候該用 |
| 19 | Mock DB vs 真 DB(testcontainers) | 19-mock-db-vs-real | 🌱 | 用 sqlite 代 PG 的坑、testcontainers 真跑 PG |
F15-E 效能測試(補 B19 的單元級)
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 20 | Benchmark 單元測試 | 20-micro-benchmark | 🌱 | Go benchmark / pytest-benchmark / JMH;跟壓測 B19 定位差異 |
F15-F 後端 TDD 實戰
B15 #06 指向通用 process/14-tdd-bdd-sdd;本節聚焦後端特有的 TDD 挑戰。
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 20-2 | Repository 層 TDD 的痛 | 20-2-repository-tdd-pain | 🌱 | mock DB 假 coverage vs testcontainers 慢測;哪些該 unit 哪些該 integration;Fake Repository 模式 |
| 20-3 | Queue Consumer TDD | 20-3-queue-consumer-tdd | 🌱 | 非同步不確定性、test helper 怎麼等、event 順序測試、idempotency 驗證 |
| 20-4 | Outside-in vs Inside-out TDD(API 層) | 20-4-outside-in-vs-inside-out | 🌱 | 從 acceptance test 往內推(London school)vs 從 domain 往外(Chicago school);API 場景選擇 |
| 20-5 | TDD + Contract Test 互動 | 20-5-tdd-contract-interaction | 🌱 | Consumer-driven contract 跟 TDD red-green-refactor 怎麼配;order of writing |
| 20-6 | TDD + Migration 節奏 | 20-6-tdd-migration | 🌱 | Schema 改動 test 會跟著改;migration test + data test 分工;上線順序 |
🔧 小實作注意事項
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 21 | Jest 測試設定 | ⛔️ backend/express/jest-setup | 🌿 | 跨系列 |
| 22 | pytest fixture 心法 | 22-pytest-fixtures | 🌱 | conftest.py、fixture scope、parametrize;後端獨特用法 |
| 23 | testcontainers 實戰 | 23-testcontainers | 🌱 | Python / Java / Go / Node 版、CI 整合 |
💣 Anti-pattern
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 24 | 後端測試 Anti-patterns | 24-backend-testing-antipatterns | 🌱 | 只測 happy path、mock 自己改的 code(循環論證)、用 production DB 跑測試、test 共用 state 有順序依賴、slow test 堆積 → CI 30 分鐘、flaky test 放給它 retry |
🧰 對應檢查工具
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 25 | 後端測試工具 | 25-backend-testing-tooling | 🌱 | pytest / JUnit / Jest / Go testing / RSpec、Coverage tool(coverage.py / JaCoCo / Istanbul)、Pact / WireMock / testcontainers |
📎 補充
| # | 主題 | Slug | Stage | 大綱 |
|---|
| S01 | Snapshot Test 在 API 的用法 | s01-api-snapshot-test | 🌱 | Jest snapshot / pytest-snapshot;API response 結構 regression 保護 |
| S02 | AI 輔助測試生成 | ⛔️ testing/10-ai-assisted-testing | 🌿 | 跨系列 |
章節進度統計
- 知識主題:25 + 2 補充 = 27 項
- 🌿 growing:5(跨系列)
- 🌱 seed:22
跨系列連結
- →
process/02-testing-strategy、14-tdd-bdd-sdd
- →
testing/05-api-contract-testing、08-test-data-management、10-ai-assisted-testing
- →
backend/express/jest-setup
- →
backend/framework/{name}/(framework 特定測試工具)
- →
backend/stress-testing/ B19(壓測跟測試的關係)