tdd-workflow
Skill335 starsChanged 10 months agoMITView on GitHub
在编写新功能、修复 bug 或重构代码时使用此 skill。强制执行测试驱动开发,覆盖率要求 80% 以上,包括单元测试、集成测试和 E2E 测试。
78 other projects use a version of this, 37 of them edited.
Adopted by
Most recently taken up by
- Lukk17/agent-standardstheir own version, first seen Oct 5, 2026
- mnzralee/claude-multi-agent-architecturetheir own version, first seen Oct 3, 2026
- JameMy0001/antigravity-skills-hubedited, first seen Oct 2, 2026
- kapadias/nonnatheir own version, first seen Oct 1, 2026
- imMamdouhaboammar/tiktok-growth-automation-meshedited, first seen Oct 1, 2026
- smitshivalkar-spectims4567/hsj-agent-skillstheir own version, first seen Sep 29, 2026
Used with
Projects with it also use kotlin-testing, ralphinho-rfc-pipeline and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
tpavanipradeepSkillkotlin-testing
Kotlin testing patterns with Kotest, MockK, coroutine testing, property-based testing, and Kover coverage. Follows TDD methodology with idiomatic Kotlin practices.
Also in 6 projects that use this
InfopibeSkillralphinho-rfc-pipeline
RFC-driven multi-agent DAG execution pattern with quality gates, merge queues, and work unit orchestration.
Also in 10 projects that use this
mryeastcodeSkillnuxt4-patterns
Nuxt 4 app patterns for hydration safety, performance, route rules, lazy loading, and SSR-safe data fetching with useFetch and useAsyncData.
Also in 5 projects that use this
saxon-ySkillconfigure-ecc
Interactive installer for Everything Claude Code — guides users through selecting and installing skills and rules to user-level or project-level directories, verifies paths, and optionally optimizes installed files.
Also in 12 projects that use this
InfopibeSkillcontent-hash-cache-pattern
Cache expensive file processing results using SHA-256 content hashes — path-independent, auto-invalidating, with service layer separation.
Also in 12 projects that use this
WorldFlowAISkillproject-guidelines-example
Also in 19 projects that use this
- +2 more from Infopibe
Other versions78 projects use a version of this.
Word for word · 0
None found.
Edited · 37
- WorldFlowAI/everything-claude-code★ 4k34% same
- xu-xiang/everything-claude-code-zh★ 2k56% same
- loulanyue/awesome-claude-notes★ 27234% same
- tpavanipradeep/everything-claude-code★ 13434% same
- templetongroup/radiant★ 11314% same
- hellangleZ/burn-in-cceverywhere-ralph★ 11234% same
- cohen-liel/hivemind★ 11034% same
- Jamkris/everything-gemini-code★ 8734% same
- codelably/harmony-claude-code★ 4362% same
- myths-labs/muse★ 3534% same
27 more not listed
Wrote their own version · 41
- ab604/claude-code-r-skills★ 205same name
- cloudnative-co/claude-code-starter-kit★ 151same name
- travisjneuman/.claude★ 101same name
- MRCalderon3D/everything-game-dev-code★ 90same name
- drvoss/everything-copilot-cli★ 47same name
- talayash/agentrium★ 42same name
- wolverin0/claude-skills★ 41same name
- VoDaiLocz/kilo-kit-mcp★ 27same name
- TSS-Blue-AI-Lab/ai-lab-agent-skills★ 25same name
- GiulSposito/r-claude-skills★ 18same name
31 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository3 other files it gives its agents.
- rules/agents.mdAGENTS.md
- examples/CLAUDE.mdCLAUDE.md
- security-reviewSkill
The file
Files
测试驱动开发工作流
此 skill 确保所有代码开发遵循 TDD 原则并具有全面的测试覆盖。
何时激活
- 编写新功能或特性
- 修复 bug 或问题
- 重构现有代码
- 添加 API 端点
- 创建新组件
核心原则
1. 代码之前先写测试
始终先写测试,然后实现代码使测试通过。
2. 覆盖率要求
- 最低 80% 覆盖率(单元 + 集成 + E2E)
- 覆盖所有边界情况
- 测试错误场景
- 验证边界条件
3. 测试类型
单元测试
- 独立的函数和工具
- 组件逻辑
- 纯函数
- 辅助函数和工具
集成测试
- API 端点
- 数据库操作
- 服务交互
- 外部 API 调用
E2E 测试(Playwright)
- 关键用户流程
- 完整工作流
- 浏览器自动化
- UI 交互
TDD 工作流步骤
步骤 1:编写用户旅程
作为 [角色],我想要 [动作],以便 [收益]
示例:
作为用户,我想要语义搜索市场,
以便即使没有精确关键词也能找到相关市场。步骤 2:生成测试用例
为每个用户旅程创建全面的测试用例:
describe('Semantic Search', () => {
it('returns relevant markets for query', async () => {
// 测试实现
})
it('handles empty query gracefully', async () => {
// 测试边界情况
})
it('falls back to substring search when Redis unavailable', async () => {
// 测试回退行为
})
it('sorts results by similarity score', async () => {
// 测试排序逻辑
})
})步骤 3:运行测试(它们应该失败)
npm test
# 测试应该失败 - 我们还没有实现步骤 4:实现代码
编写最少的代码使测试通过:
// 由测试指导的实现
export async function searchMarkets(query: string) {
// 这里是实现
}步骤 5:再次运行测试
npm test
# 测试现在应该通过步骤 6:重构
在保持测试绿色的情况下改进代码质量:
- 消除重复
- 改进命名
- 优化性能
- 增强可读性
步骤 7:验证覆盖率
npm run test:coverage
# 验证达到 80%+ 覆盖率测试模式
单元测试模式(Jest/Vitest)
import { render, screen, fireEvent } from '@testing-library/react'
import { Button } from './Button'
describe('Button Component', () => {
it('renders with correct text', () => {
render(<Button>Click me</Button>)
expect(screen.getByText('Click me')).toBeInTheDocument()
})
it('calls onClick when clicked', () => {
const handleClick = jest.fn()
render(<Button onClick={handleClick}>Click</Button>)
fireEvent.click(screen.getByRole('button'))
expect(handleClick).toHaveBeenCalledTimes(1)
})
it('is disabled when disabled prop is true', () => {
render(<Button disabled>Click</Button>)
expect(screen.getByRole('button')).toBeDisabled()
})
})API 集成测试模式
import { NextRequest } from 'next/server'
import { GET } from './route'
describe('GET /api/markets', () => {
it('returns markets successfully', async () => {
const request = new NextRequest('http://localhost/api/markets')
const response = await GET(request)
const data = await response.json()
expect(response.status).toBe(200)
expect(data.success).toBe(true)
expect(Array.isArray(data.data)).toBe(true)
})
it('validates query parameters', async () => {
const request = new NextRequest('http://localhost/api/markets?limit=invalid')
const response = await GET(request)
expect(response.status).toBe(400)
})
it('handles database errors gracefully', async () => {
// 模拟数据库失败
const request = new NextRequest('http://localhost/api/markets')
// 测试错误处理
})
})E2E 测试模式(Playwright)
import { test, expect } from '@playwright/test'
test('user can search and filter markets', async ({ page }) => {
// 导航到市场页面
await page.goto('/')
await page.click('a[href="/markets"]')
// 验证页面加载
await expect(page.locator('h1')).toContainText('Markets')
// 搜索市场
await page.fill('input[placeholder="Search markets"]', 'election')
// 等待防抖和结果
await page.waitForTimeout(600)
// 验证搜索结果显示
const results = page.locator('[data-testid="market-card"]')
await expect(results).toHaveCount(5, { timeout: 5000 })
// 验证结果包含搜索词
const firstResult = results.first()
await expect(firstResult).toContainText('election', { ignoreCase: true })
// 按状态过滤
await page.click('button:has-text("Active")')
// 验证过滤后的结果
await expect(results).toHaveCount(3)
})
test('user can create a new market', async ({ page }) => {
// 先登录
await page.goto('/creator-dashboard')
// 填写市场创建表单
await page.fill('input[name="name"]', 'Test Market')
await page.fill('textarea[name="description"]', 'Test description')
await page.fill('input[name="endDate"]', '2025-12-31')
// 提交表单
await page.click('button[type="submit"]')
// 验证成功消息
await expect(page.locator('text=Market created successfully')).toBeVisible()
// 验证重定向到市场页面
await expect(page).toHaveURL(/\/markets\/test-market/)
})测试文件组织
src/
├── components/
│ ├── Button/
│ │ ├── Button.tsx
│ │ ├── Button.test.tsx # 单元测试
│ │ └── Button.stories.tsx # Storybook
│ └── MarketCard/
│ ├── MarketCard.tsx
│ └── MarketCard.test.tsx
├── app/
│ └── api/
│ └── markets/
│ ├── route.ts
│ └── route.test.ts # 集成测试
└── e2e/
├── markets.spec.ts # E2E 测试
├── trading.spec.ts
└── auth.spec.ts模拟外部服务
Supabase 模拟
jest.mock('@/lib/supabase', () => ({
supabase: {
from: jest.fn(() => ({
select: jest.fn(() => ({
eq: jest.fn(() => Promise.resolve({
data: [{ id: 1, name: 'Test Market' }],
error: null
}))
}))
}))
}
}))Redis 模拟
jest.mock('@/lib/redis', () => ({
searchMarketsByVector: jest.fn(() => Promise.resolve([
{ slug: 'test-market', similarity_score: 0.95 }
])),
checkRedisHealth: jest.fn(() => Promise.resolve({ connected: true }))
}))OpenAI 模拟
jest.mock('@/lib/openai', () => ({
generateEmbedding: jest.fn(() => Promise.resolve(
new Array(1536).fill(0.1) // 模拟 1536 维 embedding
))
}))测试覆盖率验证
运行覆盖率报告
npm run test:coverage覆盖率阈值
{
"jest": {
"coverageThresholds": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
}
}
}常见测试错误需避免
❌ 错误:测试实现细节
// 不要测试内部状态
expect(component.state.count).toBe(5)✅ 正确:测试用户可见行为
// 测试用户看到的内容
expect(screen.getByText('Count: 5')).toBeInTheDocument()❌ 错误:脆弱的选择器
// 容易失效
await page.click('.css-class-xyz')✅ 正确:语义化选择器
// 对变化有弹性
await page.click('button:has-text("Submit")')
await page.click('[data-testid="submit-button"]')❌ 错误:没有测试隔离
// 测试相互依赖
test('creates user', () => { /* ... */ })
test('updates same user', () => { /* 依赖前一个测试 */ })✅ 正确:独立的测试
// 每个测试设置自己的数据
test('creates user', () => {
const user = createTestUser()
// 测试逻辑
})
test('updates user', () => {
const user = createTestUser()
// 更新逻辑
})持续测试
开发时的监视模式
npm test -- --watch
# 文件更改时自动运行测试预提交钩子
# 每次提交前运行
npm test && npm run lintCI/CD 集成
# GitHub Actions
- name: Run Tests
run: npm test -- --coverage
- name: Upload Coverage
uses: codecov/codecov-action@v3最佳实践
- 先写测试 - 始终 TDD
- 每个测试一个断言 - 聚焦单一行为
- 描述性测试名称 - 解释测试什么
- 准备-执行-断言 - 清晰的测试结构
- 模拟外部依赖 - 隔离单元测试
- 测试边界情况 - Null、undefined、空、大值
- 测试错误路径 - 不只是快乐路径
- 保持测试快速 - 单元测试每个 < 50ms
- 测试后清理 - 无副作用
- 查看覆盖率报告 - 识别差距
成功指标
- 达到 80%+ 代码覆盖率
- 所有测试通过(绿色)
- 没有跳过或禁用的测试
- 快速测试执行(单元测试 < 30秒)
- E2E 测试覆盖关键用户流程
- 测试在生产前捕获 bug
切记:测试不是可选的。它们是支撑自信重构、快速开发和生产可靠性的安全网。
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

