Tdd Workflow
Tdd Workflow guides developers through test-first development using the red-green-refactor pattern: write failing tests, implement minimal code to pass, then refactor while maintaining test coverage. It covers unit and integration testing strategies for both Rust and TypeScript, with practical examples including validation logic, mocking external dependencies, and coverage verification tools. All new features and fixes must meet an 80% test coverage threshold.
Tdd Workflow implements test-driven development using the red-green-refactor cycle with 80% minimum test coverage requirements.
AI-generated summary based on this skill's SKILL.md
Install
cacr92/WeReply/tdd-workflow · repository language: Python
git clone https://github.com/cacr92/WeReply
cp -r WeReply/.claude/skills/tdd-workflow ~/.claude/skills/tdd-workflowFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What is the TDD red green refactor cycle?
Tdd Workflow implements the red-green-refactor cycle as a three-phase process: first, write a failing test (red phase); second, write minimal code to make it pass (green phase); third, refactor the code while keeping tests passing (refactor phase). This cycle ensures tests drive design decisions and maintains code quality throughout development.
How do I write tests first in Tdd Workflow?
Tdd Workflow guides you to write unit and integration tests before implementation code. Start by defining test cases that describe expected behavior, then write minimal code to satisfy those tests. This test-first approach clarifies requirements upfront and prevents over-engineering, making your codebase more maintainable and bug-resistant.
How can Tdd Workflow help achieve 80% code coverage?
Tdd Workflow enforces an 80% minimum code coverage threshold for all new features and fixes. By writing tests first and using coverage verification tools, you systematically identify untested code paths. The workflow includes guidance on coverage measurement and strategies to reach and maintain this benchmark across your Rust and TypeScript projects.
How does Tdd Workflow handle mocking external dependencies?
Tdd Workflow provides practical strategies for mocking databases, APIs, and other external services to ensure test isolation. By replacing real dependencies with controlled mocks during testing, you keep tests fast, independent, and focused on your code's behavior rather than external system reliability.
What common testing pitfalls does Tdd Workflow help avoid?
Tdd Workflow addresses key pitfalls including testing implementation details instead of behavior, writing slow or interdependent tests, inadequate edge case coverage, and mishandling async operations. It emphasizes descriptive test names, proper test isolation, and validation of actual user-facing behavior to ensure test quality and maintainability.
Can Tdd Workflow be applied to bug fixes and refactoring?
Yes. Tdd Workflow extends the red-green-refactor pattern to bug fixes by first writing a test that reproduces the bug (red), then fixing the code (green), then refactoring safely. For refactoring, existing tests serve as a safety net, ensuring changes don't break functionality while you improve code structure and clarity.
SKILL.md
rendered from the published skill — quoted content, verbatim
TDD 工作流 Skill
核心原则
强制要求:所有新功能、Bug 修复、重构必须达到 80% 以上测试覆盖率。
RED-GREEN-REFACTOR 循环
1. RED(写测试,测试失败)
先写测试,验证测试会失败(因为功能尚未实现)。
2. GREEN(实现代码,测试通过)
编写最小代码使测试通过。
3. REFACTOR(重构代码,保持测试通过)
优化代码,保持所有测试通过。
工作流程
步骤 1:编写用户故事
描述期望的行为:
作为用户,我希望能够创建新的饲料配方,
以便我可以保存和管理不同的配方方案。
验收标准:
- 配方名称必填,长度 2-50 个字符
- 品种代码必填,必须是有效的品种
- 创建成功后返回配方 ID
- 创建失败时显示错误消息
步骤 2:生成测试用例
覆盖正常路径和边界情况:
Rust 测试用例:
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_create_formula_success() {
// 正常创建配方
}
#[tokio::test]
async fn test_create_formula_empty_name() {
// 配方名称为空
}
#[tokio::test]
async fn test_create_formula_name_too_long() {
// 配方名称过长
}
#[tokio::test]
async fn test_create_formula_invalid_species() {
// 品种代码无效
}
#[tokio::test]
async fn test_create_formula_database_error() {
// 数据库连接失败
}
}
TypeScript 测试用例: ```typescript describe('FormulaForm', () => { it('should create formula successfully', async () => { // 正常创建 });
it('should show error when name is empty', async () => { // 名称为空 });
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 2 files
.claude/skills/tdd-workflow/SKILL.md
.claude/skills/tdd-workflow/skill.json