Skip to content
Back to skills

Tdd

ASecurity

Use when adding a feature, fixing a bug, or changing existing behaviour. Defines acceptance criteria and a user-visible receipt, forces a failing test before any implementation, writes the minimum code to pass, runs the full suite, then refactors only while green. Includes the bug-fix variant and per-language test naming conventions.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 5, 2026
ai-agentspythongotestinggit

Security analysis

A100/100

Scanned December 5, 2026

npx -y skills add gethacked-ai/agent-security-skills --skill tdd --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Tdd?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Tdd
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gethacked-ai-tdd/badge)](https://www.skillsdirectory.com/skills/gethacked-ai-tdd)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: tdd
description: >-
  Use when adding a feature, fixing a bug, or changing existing behaviour. Defines acceptance criteria and a user-visible receipt, forces a failing test before any implementation, writes the minimum code to pass, runs the full suite, then refactors only while green. Includes the bug-fix variant and per-language test naming conventions.
metadata:
  version: "1.0"
---

# Test-Driven Development

The order is fixed: red test first, then the minimum implementation, then refactor. A test that has never failed has never been tested.

## When to Use

New features, bug fixes, behaviour changes, and any change to a contract that a caller depends on.

## Workflow

### 1. Understand the requirement

- Write the expected behaviour as acceptance criteria in plain sentences before touching code.
- List the edge cases explicitly: empty, boundary values, wrong type, unauthorized, concurrent access, and the failure path.
- Decide the **receipt**: the command the operator runs and what they will see when it works. That command is the acceptance test, and it is what proves the feature exists for a person.
- If the requirement reads ambiguously, choose the reading that serves the mission, state the choice, and name the rejected alternative. Do not stop to ask an open question.

### 2. Write the failing test first

1. Create the test file if needed, in the layout the project already uses.
2. Write one test per acceptance criterion, naming the behaviour rather than the implementation.
3. Run the test — it **must fail**, and it must fail for the right reason (an assertion failure, not an import, syntax or fixture error).
4. **If it passes, the feature already exists or the test is wrong.** Do not write implementation. Find out which, and fix the test or delete the requirement.
5. Run the test at the narrowest scope that exercises it (single file, single test id) before running the suite.

### 3. Implement the minimum

- Write the smallest amount of code that turns the test green.
- Follow an existing working pattern in the codebase — copy a real example rather than invent one.
- Run an impact check before modifying existing code: the change must not break current callers.
- Do not add behaviour that no test requires.

### 4. Verify

- The new test passes.
- The **full existing suite** passes, not only the touched file.
- Dependent features still work — re-run the affected caller's tests.
- Commit immediately: one fix, one commit, specific files staged (never `git add -A`).

### 5. Refactor (optional, only while green)

- Refactor only if the code is unclear, duplicated, or the file exceeds the project's size limit.
- Run the suite after every refactor step. A refactor that breaks a test is a bug, not a style note.

## Bug-fix variant

1. Write a test that reproduces the bug. It must fail on the current code — if it passes, the reported bug is not the bug that was reported.
2. Run the impact check on the fix location.
3. Make the minimal fix.
4. The reproducing test passes **and** the rest of the suite passes = fixed, no regressions.
5. Commit the test and the fix together, in one commit.

## Test naming

```python
# Python: test_<behavior>_<scenario>_<expected>
def test_checkout_empty_cart_returns_error():

# JS/TS: '<behavior> should <outcome> when <scenario>'
test('checkout should return error when cart is empty', () => {

# Go: Test<Behavior>_<Scenario>
func TestCheckout_EmptyCart(t *testing.T) {
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.