test-driven-development

A development method called test-driven development, or TDD, where you write a failing test, add the smallest code that passes it, and then improve the code while keeping the test passing.

In plain words
What is it for?
Use it when adding or changing functions, classes, or user flows that can be checked with unit, integration, or end-to-end tests.
Why use it?
It gives each change a clear expected behavior and catches regressions while the code is being built.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/nikolahuang/nova-cli/test-driven-development
Any agent
npx skills add Nikolahuang/nova-cli --skill test-driven-development
Clone the repo
git clone --depth 1 https://github.com/Nikolahuang/nova-cli

Made for: Claude Code, Codex.

Per session 46 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 897 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00046 $0.00897
Opus 5 $0.00023 $0.00449
Sonnet 5 $0.00009 $0.00179
Haiku 4.5 $0.00005 $0.00090

Measured 2d ago against content hash a708a44af736, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

test-driven-development scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

extensions/skills/test-driven-development/SKILL.md · 135 lines

What it actually says

测试驱动开发 (TDD)

概述

严格遵循 RED-GREEN-REFACTOR 循环。在写实现代码之前必须先写测试。

RED-GREEN-REFACTOR 循环

🔴 RED - 写失败的测试

  1. 写测试 - 描述期望行为
test('should calculate total with tax', () => {
  const result = calculateTotal(100, 0.1);
  expect(result).toBe(110);
});
  1. 运行测试 - 确认失败
npm test
# ❌ FAIL: calculateTotal is not defined
  1. 失败原因 - 理解为什么失败
  • 函数不存在?
  • 逻辑错误?
  • 接口不匹配?

🟢 GREEN - 写最小实现

  1. 写最小代码 - 只让测试通过
export function calculateTotal(amount: number, tax: rate): number {
  return amount * (1 + tax);
}
  1. 运行测试 - 确认通过
npm test
# ✓ PASS: should calculate total with tax
  1. 不要过度设计 - 只满足当前测试

🔵 REFACTOR - 改进代码

  1. 保持测试通过 - 重构时持续运行测试
  2. 消除重复 - DRY 原则
  3. 改进命名 - 更清晰的命名
  4. 优化结构 - 更好的组织

TDD 规则

必须遵守

  1. ✅ 只有测试失败时才写生产代码
  2. ✅ 只写刚好让测试通过的最小代码
  3. ✅ 每次重构前确保测试通过

禁止行为

  1. ❌ 先写实现后写测试
  2. ❌ 一次写多个测试
  3. ❌ 跳过失败的测试

测试类型

单元测试

  • 测试单个函数或类
  • 隔离依赖
  • 快速执行

集成测试

  • 测试组件交互
  • 使用真实依赖
  • 覆盖关键路径

端到端测试

  • 测试完整流程
  • 模拟用户行为
  • 覆盖主要场景

测试反模式

不要这样做

  • ❌ 测试实现细节
  • ❌ 测试私有方法
  • ❌ 过度 mock
  • ❌ 测试覆盖率至上

应该这样做

  • ✅ 测试行为,不测实现
  • ✅ 测试公共接口
  • ✅ 使用真实依赖
  • ✅ 覆盖关键路径

示例工作流

### 任务: 添加用户验证功能

#### RED
1. 写测试 `user.test.ts`
   - 测试有效邮箱格式
   - 测试无效邮箱格式
2. 运行测试 → 失败 ✓

#### GREEN  
1. 实现 `validateEmail()` 函数
2. 运行测试 → 通过 ✓

#### REFACTOR
1. 提取正则表达式常量
2. 添加类型定义
3. 运行测试 → 通过 ✓

#### COMMIT
git commit -m "feat: add email validation"

关键原则

  • 测试优先 - 永远先写测试
  • 小步前进 - 每次只写一个测试
  • 快速反馈 - 测试要快
  • 简单设计 - 只实现需要的
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 135 lines · 46 tokens per session scan A a708a44af736

Subscribe to this mod's changes

test-driven-development is a skill published in the GitHub repository Nikolahuang/nova-cli (14 stars, last pushed 4mo ago), licensed MIT. It adds 46 tokens to every session and 897 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.