Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问clear审计未展示

test-driven-development测试驱动开发

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

19,897

周安装

489

GitHub Stars

公开资料未说明

下载量

4,378
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:test-driven-development(测试驱动开发)
来源仓库:https://github.com/chunkytortoise/enterprisehub
仓库路径:skills/test-driven-development
安装命令:
npx skills add chunkytortoise/enterprisehub --skill "test-driven-development"
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

AgentSkills.tonpx skills
npx skills add chunkytortoise/enterprisehub --skill "test-driven-development"

简介

用于辅助测试先行开发与用例设计。test-driven-development 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

  • 适合先写测试再实现功能,确保需求明确。
  • 使用时需确认项目支持 TDD 流程与测试框架集成。
  • 避免测试覆盖率为唯一质量指标,关注有效性。
  • 建议配合 CI 实现自动化测试流水线。

SKILL.md

name
Test-Driven Development
description
This skill should be used when the user asks to "implement TDD", "write tests first", "follow RED-GREEN-REFACTOR", "use test-driven development", "create failing tests", or mentions TDD workflow patterns.
version
1.0.0

Test-Driven Development (TDD) Workflow

Overview

Test-Driven Development enforces the RED → GREEN → REFACTOR discipline to ensure robust, well-tested code with clean design. This skill guides implementation of the three-phase TDD cycle for both Python and TypeScript/JavaScript codebases.

TDD Three-Phase Cycle

Phase 1: RED - Write Failing Test

Write the smallest possible test that fails for the right reason.

Principles:

  • Test documents the intended behavior
  • Test must fail initially (verify failure)
  • Focus on one specific behavior per test
  • Use descriptive test names that explain the "should"

Test Structure:

// Arrange - Set up test data
// Act - Execute the behavior
// Assert - Verify the result

Phase 2: GREEN - Make Test Pass

Write the minimal implementation to make the test pass.

Principles:

  • Implement only what's needed for the test to pass
  • Don't optimize or refactor yet
  • Hardcode values if necessary
  • Focus on correctness, not elegance

Phase 3: REFACTOR - Clean Up Code

Improve the code while keeping tests green.

Focus Areas:

  • Extract repeated logic into functions
  • Improve naming and readability
  • Apply SOLID principles
  • Remove duplication
  • Optimize performance if needed

Safety Net: Run tests after each refactoring step.

Implementation Workflow

Step 1: Understand Requirements

  • Clarify the feature's expected behavior
  • Identify edge cases and error conditions
  • Define acceptance criteria

Step 2: Write Integration Test First

  • Start with a higher-level test that describes user behavior
  • Use realistic test data and scenarios
  • Focus on the public interface

Step 3: Follow TDD for Implementation

  • Write unit test (RED)
  • Implement minimal solution (GREEN)
  • Refactor and clean up (REFACTOR)
  • Repeat for each behavior

Step 4: Verify Complete Coverage

  • Run coverage report
  • Ensure all new code paths are tested
  • Add tests for any missing edge cases

Test Categories

Unit Tests

  • Test individual functions/methods in isolation
  • Use mocks for external dependencies
  • Fast execution (< 100ms each)
  • High coverage of business logic

Integration Tests

  • Test component interactions
  • Use real database/API connections where appropriate
  • Validate end-to-end workflows
  • Slower but comprehensive

Edge Case Tests

  • Null/undefined inputs
  • Empty collections
  • Boundary values (min/max)
  • Error conditions and exceptions

Language-Specific Patterns

Python (pytest)

def test_should_calculate_total_with_tax():
    # Arrange
    cart = ShoppingCart()
    cart.add_item("item1", price=100.00)

    # Act
    total = cart.calculate_total(tax_rate=0.08)

    # Assert
    assert total == 108.00

TypeScript (Jest)

describe('ShoppingCart', () => {
  it('should calculate total with tax', () => {
    // Arrange
    const cart = new ShoppingCart();
    cart.addItem('item1', 100.00);

    // Act
    const total = cart.calculateTotal(0.08);

    // Assert
    expect(total).toBe(108.00);
  });
});

Quality Gates

Before Moving to GREEN

  • [ ] Test fails for the right reason
  • [ ] Test name clearly describes the behavior
  • [ ] Test is minimal and focused
  • [ ] All existing tests still pass

Before Moving to REFACTOR

  • [ ] New test passes
  • [ ] Implementation is minimal
  • [ ] No over-engineering
  • [ ] All tests still pass

After REFACTOR

  • [ ] Code is clean and readable
  • [ ] No duplication
  • [ ] SOLID principles applied
  • [ ] All tests pass
  • [ ] Coverage maintained

Common Pitfalls to Avoid

Writing Too Much Code in GREEN

Problem: Implementing multiple features at once Solution: Write only enough code to make the current test pass

Skipping the RED Phase

Problem: Writing tests after implementation Solution: Always write failing test first, verify it fails

Not Refactoring

Problem: Accumulating technical debt Solution: Refactor immediately after GREEN, while context is fresh

Testing Implementation Details

Problem: Tests break when refactoring Solution: Test public behavior, not internal implementation

Tools and Commands

Running Tests

# Python
pytest --cov=src tests/
pytest -v --cov-report=html

# TypeScript/Jest
npm test
npm run test:coverage
npm run test:watch

Coverage Thresholds

  • Lines: 80% minimum
  • Branches: 80% minimum
  • Functions: 90% minimum
  • New code: 100% coverage required

Additional Resources

Reference Files

For detailed patterns and advanced techniques, consult:

  • references/tdd-patterns.md - Common TDD patterns and best practices
  • references/testing-pyramid.md - Testing strategy and test types
  • references/mocking-strategies.md - Mock patterns for different scenarios

Example Files

Working TDD examples in examples/:

  • examples/python-tdd-example.py - Complete Python TDD workflow
  • examples/typescript-tdd-example.ts - TypeScript TDD implementation
  • examples/api-endpoint-tdd.py - TDD for API endpoints

Scripts

Utility scripts in scripts/:

  • scripts/run-tdd-cycle.sh - Automated TDD cycle runner
  • scripts/coverage-check.sh - Coverage validation script
  • scripts/test-watch.sh - Watch mode for continuous testing

TDD in Context

When to Use TDD

  • New feature development
  • Bug fixes with regression tests
  • Refactoring existing code
  • API design and validation

When to Consider Alternatives

  • Exploratory coding/prototyping
  • UI/UX experimentation
  • Performance optimization spikes
  • External system integration discovery

Success Metrics

Quantitative

  • Code coverage > 80%
  • Test execution time < 5 minutes
  • Test failure rate < 5%
  • Defect density reduction

Qualitative

  • Confidence in refactoring
  • Clear behavior documentation
  • Faster debugging cycles
  • Improved code design

Apply TDD discipline consistently to build robust, maintainable code with comprehensive test coverage and clean architecture.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

windsurf

26.99%
按下载量换算1,182

OpenCode

22.86%
按下载量换算1,001

Codex

19.27%
按下载量换算844

Claude Code

12.65%
按下载量换算554

Antigravity

7.82%
按下载量换算342

Gemini CLI

3.7%
按下载量换算162

安全审计

暂无安全审计结果可展示。

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills