Communitygithub.com

Lev-it/lev-skills

測試驅動開發。當使用者想以測試優先的方式建置功能或修正錯誤、提到「紅-綠-重構」,或需要整合測試時使用。

lev-skills 是什麼?

這項技能實作了嚴格的測試驅動開發(TDD)方法論,強調透過公開介面驗證行為,而非實作細節。它支援垂直切片(vertical slicing)工作流程,透過「追蹤子彈」(tracer bullets)逐步迭代:一次撰寫一個測試、實作最簡程式碼使其通過,然後重構。此技能明確反對「水平切片」(horizontal slicing)的反模式,因為該模式會產生與實作耦合、無法在重構後存活的測試。它適用於任何使用測試優先方法的專案,並能與程式碼庫中的 CONTEXT.md、tests.md、mocking.md 和 refactoring.md 檔案整合,提供完整的 TDD 流程指引。使用者可以在規劃階段與技能互動,確認介面變更和行為優先順序,然後逐步進行紅-綠-重構循環,並在每次循環結束時使用檢查清單確保測試品質。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Lev-it/lev-skills/tree/HEAD/.claude/skills/tdd

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

測試驅動開發

哲學

核心原則:測試應透過公開介面驗證行為,而非實作細節。程式碼可以完全改變;測試不該受到影響。

好的測試屬於整合風格:它們透過公開 API 執行真實的程式碼路徑。它們描述的是系統做什麼,而非如何做。好的測試讀起來像一份規格說明——「使用者可以使用有效的購物車結帳」精準告訴你存在什麼功能。這類測試能經得起重構,因為它們不在乎內部結構。

壞的測試則與實作緊密耦合。它們模擬內部協作者、測試私有方法,或透過外部方式驗證(例如直接查詢資料庫,而非使用介面)。警告信號:當你重構時測試失敗,但行為並未改變。如果你重新命名內部函數後測試失敗,那些測試就是在測試實作,而不是測試行為。

請參閱 tests.md 取得範例,以及 mocking.md 取得模擬指引。

反模式:水平切片

不要先把所有測試寫完,再寫所有實作。這就是「水平切片」——把 RED 階段當成「寫所有測試」,GREEN 階段當成「寫所有程式碼」。

這樣會產生糟糕的測試:

  • 大量撰寫的測試測試的是想像的行為,而非實際的行為
  • 最終你測試的是事物的形狀(資料結構、函數簽名),而非使用者面對的行為
  • 測試對真實變更不敏感——行為壞掉時測試仍通過,行為正常時測試卻失敗
  • 你在超出自己理解範圍的情況下,在瞭解實作之前就確定了測試結構

正確做法:透過追蹤子彈進行垂直切片。一個測試 → 一個實作 → 重複。每個測試都回應你從前一個循環中學到的東西。因為你剛寫完程式碼,所以你確切知道哪些行為重要,以及如何驗證它。

錯誤(水平):
  RED:   test1, test2, test3, test4, test5
  GREEN: impl1, impl2, impl3, impl4, impl5

正確(垂直):
  RED→GREEN: test1→impl1
  RED→GREEN: test2→impl2
  RED→GREEN: test3→impl3
  ...

工作流程

1. 規劃

在探索程式碼庫時,請閱讀 CONTEXT.md(如果存在),以便測試名稱和介面詞彙與專案的領域語言一致,並尊重你所觸及區域中的 ADR。

在撰寫任何程式碼之前:

  • 與使用者確認需要哪些介面變更
  • 與使用者確認要測試哪些行為(優先排序)
  • 找出深度模組的機會(小介面、深層實作)——執行 /codebase-design 技能以取得詞彙和可測試性檢查
  • 列出要測試的行為(而非實作步驟)
  • 取得使用者對計畫的批准

問:「公開介面應該長什麼樣子?哪些行為最重要要測試?」

你無法測試所有東西。 與使用者確認哪些行為最重要。將測試工作集中在關鍵路徑和複雜邏輯上,而非每個可能的邊緣情況。

2. 追蹤子彈

撰寫一個測試,確認系統中的一件事:

紅:   撰寫第一個行為的測試 → 測試失敗
綠:   撰寫最簡程式碼使其通過 → 測試通過

這就是你的追蹤子彈——證明路徑端到端可行。

3. 增量循環

針對每個剩餘行為:

紅:   撰寫下一個測試 → 失敗
綠:   最簡程式碼使其通過 → 通過

規則:

  • 一次只寫一個測試
  • 只寫足以通過目前測試的程式碼
  • 不要預先設想未來的測試
  • 保持測試專注於可觀察的行為

4. 重構

在所有測試通過後,尋找重構候選:

  • 消除重複
  • 加深模組(將複雜性移到簡單介面背後)
  • 在自然之處應用 SOLID 原則
  • 思考新程式碼對既有程式碼揭示了什麼
  • 在每個重構步驟後執行測試

絕不在紅燈時重構。 先達到綠燈。

每次循環的檢查清單

[ ] 測試描述的是行為,而非實作
[ ] 測試只使用公開介面
[ ] 測試在內部重構後仍能存活
[ ] 程式碼是為此測試所需的最簡版本
[ ] 未加入推測性的功能

Individual skills in this repo

This repo contains 11 individual skills — each has its own dedicated page.

Lev-it/lev-skills

Ask which skill or flow fits your situation. A router over the user-invoked skills in this repo.

Lev-it/lev-skills

Premium brand-kit image generation skill for creating high-end brand-guidelines boards, logo systems, identity decks, and visual-world presentations. Trained for minimalist, cinematic, editorial, dark-tech, luxury, cultural, security, gaming, developer-tool, and consumer-app brand systems. Optimized for intentional logo concepting, refined composition, sparse typography, strong symbolic meaning, premium mockups, art-directed imagery, and flexible grid layouts.

Lev-it/lev-skills

Compact the current conversation into a handoff document for another agent to pick up.

Lev-it/lev-skills

Ink terminal renderer for json-render that turns JSON specs into interactive terminal UIs. Use when working with @json-render/ink, building terminal UIs from JSON, creating terminal component catalogs, or rendering AI-generated specs in the terminal.

Lev-it/lev-skills

Interactive QA session where user reports bugs or issues conversationally, and the agent files GitHub issues. Explores the codebase in the background for context and domain language. Use when user wants to report bugs, do QA, file issues conversationally, or mentions "QA session".

Lev-it/lev-skills

Facilitate a structured sprint retrospective — what went well, what didn't, and prioritized action items with owners and deadlines. Use when running a retrospective, reflecting on a sprint, creating action items from team feedback, or learning how to run effective retros.

Lev-it/lev-skills

Review the changes since a fixed point (commit, branch, tag, or merge-base) along two axes — Standards (does the code follow this repo's documented coding standards?) and Spec (does the code match what the originating issue/PRD asked for?). Runs both reviews in parallel sub-agents and reports them side by side. Use when the user wants to review a branch, a PR, work-in-progress changes, or asks to "review since X".

Lev-it/lev-skills

Teach the user a new skill or concept, within this workspace.

Lev-it/lev-skills

Turn the current conversation into a PRD and publish it to the project issue tracker — no interview, just synthesis of what you've already discussed.

Lev-it/lev-skills

Move issues through a state machine of triage roles — categorise, reproduce, grill if needed, and write agent-ready briefs.

Lev-it/lev-skills

Create product backlog items in Why-What-Acceptance format — independent, valuable, testable items with strategic context. Use when writing structured backlog items, breaking features into work items, or using the WWA format.

相關技能