← 返回
开发者工具 中文

test-driven-development

Unified TDD skill with three input modes — from spec, from task, or from description. Enforces test-first development using repository patterns, with proptes...
统一TDD技能,支持规范、任务或描述三种输入模式。通过仓库模式强制执行测试先行开发,并附带专业测试生成功能。
imbeasting
开发者工具 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 1
Stars
📥 1,212
下载
💾 61
安装
1
版本
#latest

概述

Test-Driven Development

Overview

One skill for all TDD workflows. Enforces test-first development using existing repository patterns. Three input modes handle different entry points — specs, task files, or ad-hoc descriptions — but the core cycle is always RED → GREEN → REFACTOR.

Input Modes

Detect the input type and follow the corresponding mode:

Mode A: From Spec (.spec.md)

Use when the input references a .spec.md file with Given/When/Then acceptance criteria.

  1. Locate and parse the spec file — extract all Given/When/Then triples
  2. Generate one test stub per criterion with todo!() bodies:

```rust

/// Spec: — Criterion #

/// Given

/// When

/// Then

#[test]

fn _criterion__() {

todo!("Implement: ");

}

```

  1. Verify stubs compile but fail: cargo test --no-run -p
  2. Proceed to the TDD Cycle to make stubs pass

Programmatic support: ralph_core::preflight::{extract_acceptance_criteria, extract_criteria_from_file, extract_all_criteria} can parse criteria from spec files.

Mode B: From Task (.code-task.md)

Use when the input references a .code-task.md file or a specific implementation task.

  1. Read the task and identify acceptance criteria or requirements
  2. Discover patterns (see Pattern Discovery)
  3. Design test scenarios covering normal operation, edge cases, and error conditions
  4. Write failing tests for all requirements before any implementation
  5. Proceed to the TDD Cycle

Mode C: From Description

Use for ad-hoc tasks without a spec or task file.

  1. Clarify requirements from the description
  2. Discover patterns (see Pattern Discovery)
  3. Write failing tests targeting the described behavior
  4. Proceed to the TDD Cycle

Pattern Discovery

Before writing tests, discover existing conventions:

rg --files -g "crates/*/tests/*.rs"
rg -n "#\[cfg\(test\)\]" crates/

Read 2-3 relevant test files near the target code. Mirror:

  • Test module layout, naming, and assertion style
  • Fixture helpers and test utilities
  • Use of tempfile, scenarios, or harnesses

TDD Cycle

1) RED — Failing Tests

  • Write tests for the exact behavior required
  • Run tests to confirm failure for the right reason
  • If tests pass without implementation, the test is wrong

2) GREEN — Minimal Implementation

  • Write the minimum code to make tests pass
  • No extra features or refactoring during this step

3) REFACTOR — Clean Up

  • Improve implementation and tests while keeping tests green
  • Align with surrounding codebase conventions
  • Re-run tests after every change

Proptest Guidance

Use proptest only when ALL of:

  • Function is pure (no I/O, no time, no globals)
  • Deterministic output for given input
  • Non-trivial input space or edge cases
proptest! {
    #[test]
    fn round_trip(input in "[a-z0-9]{0,32}") {
        let encoded = encode(input.as_str());
        let decoded = decode(&encoded).expect("should decode");
        prop_assert_eq!(decoded, input);
    }
}

Don't introduce proptest as a new dependency without strong justification.

Backpressure Integration

Include coverage evidence in completion events:

ralph emit "build.done" "tests: pass, lint: pass, typecheck: pass, audit: pass, coverage: pass (82%)"

Run cargo tarpaulin --out Html --output-dir coverage --skip-clean when feasible. If coverage cannot be run, state why and include targeted test evidence instead.

Test Location Rules

  • Spec maps to a single module → inline #[cfg(test)] tests
  • Spec spans multiple modules → integration test in crates//tests/
  • CLI behavior → crates/ralph-cli/tests/
  • Follow existing patterns in the target crate

Anti-Patterns

  • Writing implementation before tests
  • Generating tests that pass without implementation
  • Copying tests from other crates without adapting to local patterns
  • Adding proptest when a simple example test suffices
  • Emitting completion events without coverage evidence

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-30 06:52 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

content-creation

mcp-builder

imbeasting
创建高质量 MCP(模型上下文协议)服务器的指南,该服务器通过精心设计的工具使 LLM 能够与外部服务交互。
★ 0 📥 612
developer-tools

Gog

steipete
Google Workspace 命令行工具,支持 Gmail、日历、云端硬盘、通讯录、表格和文档。
★ 921 📥 185,930
developer-tools

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 672 📥 324,544