with one click
gen-test-cases
根據選取的程式碼或功能範圍,自動產生測試案例清單與對應的測試程式,並驗證結果
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
根據選取的程式碼或功能範圍,自動產生測試案例清單與對應的測試程式,並驗證結果
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
| name | Gen Test Cases |
| description | 根據選取的程式碼或功能範圍,自動產生測試案例清單與對應的測試程式,並驗證結果 |
扮演一位經驗豐富的軟體測試專家,根據以下步驟進行協作:
掃描專案根目錄,判斷以下兩件事:
1a. 專案層級(layers)
讀取根目錄結構,識別有哪些層級存在:
| 偵測到的目錄或特徵 | 識別為 |
|---|---|
frontend/、client/、web/,或根目錄有 vite.config.* / next.config.* | frontend |
backend/、server/、api/,或根目錄有 package.json 且無前端特徵 | backend |
src/ 且同時含 UI 與 API 程式碼 | app(monolith) |
其他服務目錄(如 worker/、jobs/、infra/) | 以目錄名稱作為 layer 名 |
1b. 測試框架
對每個識別到的 layer,檢查:
package.json 的 devDependencies / scripts.testjest.config.*、vitest.config.*、pytest.ini、go.mod 等設定檔__tests__/、tests/、spec/ 等)的位置與命名慣例1c. 建立 doc/test 子目錄
依識別到的 layers 建立對應子目錄,例如:
doc/test/frontend/ + doc/test/backend/doc/test/frontend/doc/test/app/doc/test/<service-name>/(每個服務一個)若
doc/test/已存在且有子目錄,沿用現有結構,不重建。
1d. 掃描現有測試檔案
對指定範圍對應的測試檔(如 auth.test.ts、Login.test.tsx):
describe / it / test 描述根據指定範圍,依 layer 分別撰寫測試案例:
references/test-doc-template.mddoc/test/<layer>/ 子目錄,一個功能一個檔案參考 doc/test/<layer>/ 的案例文件,依照 STEP 1 偵測到的框架與慣例撰寫測試程式:
src/__tests__/ 或 tests/ 下建立)撰寫規則:
describe() 必須為「測試類型」(對應 Markdown 標題的【】內文字,如「Mock API」、「表單驗證」、「CSRF 守衛」)it() / test() 的描述直接使用 Markdown 原文(## 標題去掉狀態符號和【測試類型】後的文字),不翻譯、不重新命名整併現有測試檔規則(當 STEP 1d 發現既有測試時):
it() / test() 的描述改為對應 Markdown 案例的原文describe(測試類型) 包裹describe 區塊內describe("auth", () => {
describe("成功登入", () => {
test("正確帳密 → 200、回傳 user + csrfToken、Set-Cookie httpOnly", ...)
})
describe("帳號鎖定", () => {
test("連續 5 次失敗鎖定帳號", ...)
test("4 次失敗尚未鎖定", ...) // 新增
})
})
執行對應 layer 的測試指令(從 STEP 1 偵測到的 scripts.test 或框架預設指令)。
若測試通過,到對應的 doc/test/<layer>/ Markdown 檔將已通過的案例打勾([ ] → [x])。
若測試不符預期,重複 STEP 3–4,最多 5 次。5 次仍失敗則停下來說明原因與建議方向。