Skip to content

Commit 1b61eb7

Browse files
author
薛華慶, james.hsueh
committed
feat: add agent for bdd
1 parent afabca4 commit 1b61eb7

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed

.claude/commands/sdd-bds.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
description: BDD × TDD - 從 feature 生成紅燈 integration tests
3+
---
4+
5+
# SDD-BDS: BDD × TDD 紅燈測試
6+
7+
**需求:** {{prompt}}
8+
9+
**角色:** 協助開發者實踐 BDD(行為驅動開發)× TDD(測試驅動開發)
10+
11+
**目標:**
12+
1. 從 feature 需求生成可編譯但會失敗的 integration tests(紅燈)
13+
2. 驅動開發流程:紅燈 → 綠燈 → 重構
14+
15+
## 核心原則
16+
- **BDD**:測試描述業務行為,非技術實作
17+
- **TDD**:測試先行、可編譯、會失敗(紅燈)
18+
- **Integration**:測試真實整合場景(API/DB/Service)
19+
20+
## 執行步驟
21+
22+
### 1. 掃描專案與框架偵測
23+
```bash
24+
ls -la | grep -E "package.json|requirements.txt|go.mod|pom.xml"
25+
find . -name "*test*" -o -name "*spec*" | head -3
26+
```
27+
28+
**框架優先順序:** 使用者指定 > 專案既有 > 預設
29+
- **TypeScript**: Jest/Vitest + Supertest
30+
- **Python**: pytest + httpx
31+
- **Go**: testing + testify
32+
33+
### 2. 測試場景(至少 3 個)
34+
- 正常流程
35+
- 邊界情況
36+
- 錯誤處理
37+
38+
### 3. 測試結構(BDD 風格)
39+
40+
每個測試遵循 **Arrange-Act-Assert** 模式:
41+
- **Arrange**: 準備測試資料與環境
42+
- **Act**: 執行被測試的行為
43+
- **Assert**: 驗證預期結果
44+
45+
**測試命名:** 描述業務行為,非技術細節
46+
-`應該拒絕無效的電子郵件格式`
47+
-`當庫存不足時應該返回錯誤`
48+
-`test_validate_email_regex`
49+
50+
## 測試要求
51+
- [ ] 可編譯通過
52+
- [ ] 執行會失敗(功能未實作)
53+
- [ ] 涵蓋正常/邊界/錯誤
54+
- [ ] Arrange-Act-Assert 結構
55+
- [ ] setup/teardown
56+
57+
## 驗證
58+
```bash
59+
# 編譯檢查
60+
npx tsc --noEmit # TS
61+
python -m py_compile tests/**/*.py # Python
62+
go build ./... # Go
63+
64+
# 執行測試(預期失敗/紅燈)
65+
npm test / pytest -v / go test -v
66+
```
67+
68+
## BDD × TDD 工作流程
69+
70+
1. **紅燈階段**(本指令):生成描述業務行為的失敗測試
71+
2. **綠燈階段**:實作最小程式碼讓測試通過(可用 `/sdd-impl`
72+
3. **重構階段**:優化程式碼,保持測試通過
73+
74+
## 輸出位置
75+
`tests/integration/{feature}.test.{ext}` 或依專案既有結構
76+
77+
開始生成紅燈測試。

.codex/prompts/sdd-bds.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
description: BDD × TDD - 從 feature 生成紅燈 integration tests
3+
---
4+
5+
# SDD-BDS: BDD × TDD 紅燈測試
6+
7+
**需求:** {{prompt}}
8+
9+
**角色:** 協助開發者實踐 BDD(行為驅動開發)× TDD(測試驅動開發)
10+
11+
**目標:**
12+
1. 從 feature 需求生成可編譯但會失敗的 integration tests(紅燈)
13+
2. 驅動開發流程:紅燈 → 綠燈 → 重構
14+
15+
## 核心原則
16+
- **BDD**:測試描述業務行為,非技術實作
17+
- **TDD**:測試先行、可編譯、會失敗(紅燈)
18+
- **Integration**:測試真實整合場景(API/DB/Service)
19+
20+
## 執行步驟
21+
22+
### 1. 掃描專案與框架偵測
23+
```bash
24+
ls -la | grep -E "package.json|requirements.txt|go.mod|pom.xml"
25+
find . -name "*test*" -o -name "*spec*" | head -3
26+
```
27+
28+
**框架優先順序:** 使用者指定 > 專案既有 > 預設
29+
- **TypeScript**: Jest/Vitest + Supertest
30+
- **Python**: pytest + httpx
31+
- **Go**: testing + testify
32+
33+
### 2. 測試場景(至少 3 個)
34+
- 正常流程
35+
- 邊界情況
36+
- 錯誤處理
37+
38+
### 3. 測試結構(BDD 風格)
39+
40+
每個測試遵循 **Arrange-Act-Assert** 模式:
41+
- **Arrange**: 準備測試資料與環境
42+
- **Act**: 執行被測試的行為
43+
- **Assert**: 驗證預期結果
44+
45+
**測試命名:** 描述業務行為,非技術細節
46+
-`應該拒絕無效的電子郵件格式`
47+
-`當庫存不足時應該返回錯誤`
48+
-`test_validate_email_regex`
49+
50+
## 測試要求
51+
- [ ] 可編譯通過
52+
- [ ] 執行會失敗(功能未實作)
53+
- [ ] 涵蓋正常/邊界/錯誤
54+
- [ ] Arrange-Act-Assert 結構
55+
- [ ] setup/teardown
56+
57+
## 驗證
58+
```bash
59+
# 編譯檢查
60+
npx tsc --noEmit # TS
61+
python -m py_compile tests/**/*.py # Python
62+
go build ./... # Go
63+
64+
# 執行測試(預期失敗/紅燈)
65+
npm test / pytest -v / go test -v
66+
```
67+
68+
## BDD × TDD 工作流程
69+
70+
1. **紅燈階段**(本指令):生成描述業務行為的失敗測試
71+
2. **綠燈階段**:實作最小程式碼讓測試通過(可用 `/sdd-impl`
72+
3. **重構階段**:優化程式碼,保持測試通過
73+
74+
## 輸出位置
75+
`tests/integration/{feature}.test.{ext}` 或依專案既有結構
76+
77+
開始生成紅燈測試。

0 commit comments

Comments
 (0)