Skip to content
Back to skills

Tdd Guide

ASecurity

Guide red-green-refactor TDD with test generation, coverage-gap analysis, and multi- framework support. Use when writing tests first, analyzing coverage, generating test stubs, or converting tests between Jest, Pytest, JUnit, and Vitest.

  • 1,271 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added May 30, 2026
ai-agentstypescriptpythongojavabashtestingrefactoringgitapidevops

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 18 files and shows the line behind each finding

Scanned December 4, 2026

npx -y skills add borghei/Claude-Skills --skill tdd-guide --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Tdd Guide?

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

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

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-guide
description: >
  Guide red-green-refactor TDD with test generation, coverage-gap analysis, and multi-
  framework support. Use when writing tests first, analyzing coverage, generating test stubs,
  or converting tests between Jest, Pytest, JUnit, and Vitest.
license: MIT + Commons Clause
metadata:
  version: 1.1.0
  author: borghei
  category: engineering
  domain: testing
  updated: 2026-11-08
  tags: [tdd, test-driven-development, testing, red-green-refactor]
---
# TDD Guide

The agent guides red-green-refactor TDD workflows, generates framework-specific test stubs from requirements, parses coverage reports to identify prioritized gaps, and reports per-test quality findings (missing assertions, sleeps, branching, vague names). Supports Jest, Pytest, JUnit, Vitest, and Mocha.

## Core Capabilities

- **Red-green-refactor guidance** — phase validation (RED/GREEN/REFACTOR), cycle tracking, refactoring suggestions
- **Test generation** — produce test cases and framework-specific stubs from user stories, acceptance criteria, and API specs
- **Coverage gap analysis** — parse LCOV/JSON/XML reports, identify files below threshold, prioritize P0/P1/P2
- **Test quality findings** — per-test assertion counts and smell detection with line quotes and fixes
- **Multi-framework support** — convert a test file's suite and test names to Jest, Vitest, Mocha, Pytest, unittest, JUnit or TestNG (bodies become failing stubs that point at the source line to port), and generate seeded fixtures/mocks

## When to Use

- Writing a failing test first for a new feature (test-driven development)
- Analyzing coverage reports to find and prioritize gaps
- Generating test stubs from requirements or API specs
- Converting tests between frameworks or scaffolding fixtures/mocks
- Assessing test quality and detecting smells before merge

## Clarify First

Before generating tests or analyzing coverage, settle the inputs below. When one is missing or vague and would change the result, ask about it; when it wouldn't, use a sensible default and say which one you used.

- **Framework & language:** Jest / Vitest / Pytest / JUnit / Mocha (changes the generated stubs and any conversion).
- **Task:** generate from requirements / analyze coverage / guide a red-green-refactor cycle / convert tests (selects the tool).
- **Source input:** the user story / acceptance criteria, or the coverage report (LCOV/JSON/XML) to parse (the script's input).

Ask about the two or three inputs that matter most for this request, not the whole list. If the user wants a result straight away, produce it and state your assumptions at the top.

## Quick Start

`scripts/tdd.py` is the command-line entry point. Its most useful job is the coverage gate:
it parses LCOV, Istanbul JSON or Cobertura XML, lists every file below the threshold with
its uncovered lines, and exits 1 while any gap remains.

```bash
python3 scripts/tdd.py coverage assets/sample_coverage_gaps.lcov --threshold 80     # exit 1, lists gaps
python3 scripts/tdd.py coverage assets/sample_coverage_report.lcov --threshold 80   # exit 0
python3 scripts/tdd.py generate assets/sample_input_python.json --module discount  # pytest stubs
python3 scripts/tdd.py quality assets/flawed_tests.py --format json               # exit 1, findings with fixes
python3 scripts/tdd.py coverage assets/sample_coverage_gaps.lcov --format markdown  # paste-ready gap report
python3 scripts/tdd.py phase red --test assets/sample_jest_test.ts --status failed   # exit 0: RED step done
python3 scripts/tdd.py fixtures assets/sample_fixture_spec.json --fixture-format python
python3 scripts/tdd.py convert assets/sample_jest_test.ts --to pytest
```

## Tools Overview

| Subcommand | What it does | Key flags |
|------------|--------------|-----------|
| `coverage <report>` | Per-file line/branch gaps, uncovered lines, prioritised P0-P2 recommendations | `--threshold` (default 80), `--format text/json/markdown` |
| `generate <input.json>` | Test stubs from user stories, acceptance criteria, error and edge cases (Jest, Vitest, Pytest, JUnit, Mocha) | `--framework`, `--module`, `-o`, `--format` |
| `quality <test file>` | Reads each test (Python, JS/TS, Java); flags no-assertion, assertion-roulette (>5, heuristic), sleep, conditional logic, vague or duplicate names, each with the line quoted and a fix. No composite score. Exits 1 on findings | `--format text/json` |
| `phase red\|green\|refactor` | Checks one step: RED needs a test with assertions that failed; GREEN needs passing tests and a small implementation; REFACTOR needs tests still passing. Quality improvement is a heuristic (distinct lines, identifier length) and shows `--` when nothing is measurable | `--test`, `--impl`, `--before`/`--after`, `--status failed\|passed` |
| `fixtures <spec.json>` | Boundary values per field, edge-case scenarios (auth, payment, form, api, file_upload) and seeded mock records from a schema | `--count`, `--seed`, `--fixture-format json\|python\|yaml`, `-o` |
| `convert <test file>` | Reads Python, JS/TS or Java tests and writes the same suite and test names in the target framework; each body is a failing stub citing the source line, so assertions are ported by hand | `--to`, `-o`, `--format` |

Real output of `python3 scripts/tdd.py quality assets/flawed_tests.py`:

```
Read 2 test(s), 7 assertion(s) from assets/flawed_tests.py
  line 3 [no-assertion] def test1():
    '1' runs code but checks nothing, so it cannot fail
    fix: add an assertion on the return value or side effect; for an error path use toThrow() / pytest.raises
  ...
FIX 6 issue(s)
```

Generated stubs raise or throw until you write the real assertion, so they start RED by
design; a stub that passes before the code exists proves nothing.

Exit codes: `0` ok (coverage: every file meets the threshold; quality: no findings; phase: step complete); `1` coverage
gaps found, quality findings, or the phase step is not complete; `2` bad input (missing or empty file, unknown
report format, invalid JSON, unknown framework, a phase step without its files or `--status`,
a fixture spec with nothing to generate, a file with no tests to convert or score).

Every module behind these subcommands can also be imported with `PYTHONPATH=scripts`, as shown
in `references/tool-reference.md`.

## Workflow

1. RED: write or generate a failing test for the next behaviour; run it and confirm it fails for the expected reason.
2. GREEN: write the least code that passes; run the suite.
3. REFACTOR: clean up with the suite green; run it again.
4. Validate coverage with the project's own test runner producing a report, then `tdd.py coverage` on it. Done when it exits 0 at the agreed threshold and every new branch has a test that failed before the code existed.

## References

Load the reference that matches the task — keep this file lean and pull detail on demand:

- **[references/workflows.md](references/workflows.md)** — step-by-step procedures for TDD-ing a feature, analyzing coverage gaps, and generating tests from requirements, each with validation checkpoints. Read when starting any of the three core workflows.
- **[references/tool-reference.md](references/tool-reference.md)** — complete API for all eight scripts (constructors, methods, parameters, worked examples) plus the tools summary table. Read when you need exact module names or method signatures.
- **[references/tdd-best-practices.md](references/tdd-best-practices.md)** — red-green-refactor discipline, naming/structure guidelines, test quality principles, and coverage goals. Read when deciding how to write or evaluate tests.
- **[references/framework-guide.md](references/framework-guide.md)** — framework selection matrix, configuration, and test patterns for TypeScript/JS, Python, and Java, with version requirements. Read when setting up or choosing a test framework.
- **[references/ci-integration.md](references/ci-integration.md)** — coverage report flow, GitHub Actions examples (Jest/Pytest/JaCoCo), quality gates, and trend tracking. Read when wiring coverage and quality gates into CI.
- **[references/troubleshooting-and-quality.md](references/troubleshooting-and-quality.md)** — anti-patterns, troubleshooting table, and success criteria. Read when tests behave unexpectedly or when defining the test-quality bar.

## Scope & Limitations

**This skill covers:**
- Unit test generation, scaffolding, and stub creation for Jest, Pytest, JUnit, Vitest, and Mocha
- Static coverage report parsing (LCOV, JSON/Istanbul, XML/Cobertura) with gap identification and prioritized recommendations
- Red-green-refactor workflow guidance with phase validation and cycle tracking
- Test quality findings (missing assertions, sleeps, branching, vague names) per test

**This skill does NOT cover:**
- Integration, end-to-end, or performance test generation -- see `senior-qa` for E2E patterns and `senior-devops` for load testing
- Runtime test execution or live coverage measurement -- scripts perform static analysis only; you must run your test suite externally
- Visual/snapshot testing or browser-based test workflows -- use Playwright, Cypress, or Storybook for UI-level testing
- Security-focused test generation (fuzz testing, penetration testing) -- see `senior-security` and `senior-secops` skills

## Anti-Patterns

### Tests Written After the Code
**Mistake:** Writing the implementation first, then adding tests that mirror it.
**Why it happens:** It feels faster, and the tests pass on the first run.
**Instead:** Watch each test fail before the code exists. A test that never failed may not be able to fail.

### Chasing the Coverage Number
**Mistake:** Adding assertion-free tests to push a file over the threshold.
**Why it happens:** The gate checks lines executed, not behaviour verified.
**Instead:** Run `tdd.py quality` alongside `coverage`; low assertions per test with high coverage is the signature of this mistake.

### Committing Generated Stubs Unfilled
**Mistake:** Leaving generated stubs in the suite with placeholder bodies.
**Why it happens:** They look like progress.
**Instead:** The stubs fail until filled in, on purpose. Fill each one or delete it before merging.

## Files

| File | Purpose |
|------|---------|
| `scripts/tdd.py` | CLI: `coverage`, `generate`, `quality`, `phase`, `fixtures`, `convert` |
| `scripts/coverage_analyzer.py`, `test_generator.py`, `metrics_calculator.py`, `format_detector.py`, `output_formatter.py` | Libraries behind `coverage`, `generate` and `quality` |
| `scripts/tdd_workflow.py`, `fixture_generator.py`, `framework_adapter.py` | Libraries behind `phase`, `fixtures` and `convert` |
| `assets/sample_coverage_report.lcov` | Fully covered report (coverage exits 0) |
| `assets/sample_coverage_gaps.lcov` | Report with an untested function and branches (exits 1) |
| `assets/sample_input_python.json`, `sample_input_typescript.json` | Requirements inputs for `generate` |
| `assets/sample_fixture_spec.json` | Fixture spec (schema, boundaries, payment edge cases) for `fixtures` |
| `assets/sample_jest_test.ts` | Jest test file for `convert` and `phase red` |
| `assets/sound_tests.py`, `flawed_tests.py`, `malformed_tests.txt` | `quality` samples (exit 0, 1, 2); `malformed_input.json`, `malformed_coverage.lcov` are exit-2 inputs |
| `assets/contract.json` | Declared runs checked by `scripts/skill_contract_check.py` |
| `assets/expected_output.json` | Example combined output (illustrative, not a live run) |
| `references/*.md` | Workflows, API reference, practices, frameworks, CI, troubleshooting |

Files in this skill

  • HOW_TO_USE.md7 KB
  • README.md18.1 KB
  • SKILL.md27.2 KB
  • assets/expected_output.json2.3 KB
  • assets/sample_coverage_report.lcov615 B
  • assets/sample_input_python.json1.4 KB
  • assets/sample_input_typescript.json1.4 KB
  • references/ci-integration.md3.9 KB
  • references/framework-guide.md4.2 KB
  • references/tdd-best-practices.md3.4 KB
  • scripts/coverage_analyzer.py15.1 KB
  • scripts/fixture_generator.py14 KB
  • scripts/format_detector.py11.9 KB
  • scripts/framework_adapter.py14.5 KB
  • scripts/metrics_calculator.py15.1 KB
  • scripts/output_formatter.py12.4 KB
  • scripts/tdd_workflow.py16.6 KB
  • scripts/test_generator.py14.3 KB

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.