搜索

PythonReactSEOPDF
GitHub Skill

tdd

Use when implementing any feature or bugfix - write test first, watch it fail, then implement

TKontu☆ 0 仓库 Stars0 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

Test-Driven Development

The Rule

NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST

Red-Green-Refactor Cycle

RED - Write Failing Test
def test_validates_empty_email():
    result = validate_email("")
    assert result.is_valid is False
    assert result.error == "Email required"

Run it. Watch it fail. Confirm it fails for the right reason (missing feature, not typo).

GREEN - Minimal Code

Write the simplest code that makes the test pass:

def validate_email(email: str) -> ValidationResult:
    if not email:
        return ValidationResult(is_valid=False, error="Email required")
    return ValidationResult(is_valid=True, error=None)

Run tests. All pass.

REFACTOR

Clean up only if needed. Keep tests green.

Repeat

Next failing test for next behavior.

Verification

pytest path/to/test.py -v

Must see:

  • Test fails first (RED)
  • Test passes after implementation (GREEN)
  • All other tests still pass

Quick Checklist

  • Test written before code
  • Watched test fail
  • Minimal implementation
  • All tests pass
  • No skipped steps

Anti-Patterns

Bad Good
Write code, then test Write test, watch fail, then code
"I'll test after" Test first proves it works
Multiple behaviors per test One behavior per test
Test passes immediately Test must fail first

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-01-20
索引更新时间
2026-01-26
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!