TDD Workflow

VerifiedSafe

Forces a test-driven development (TDD) workflow, automatically activating when implementing new features, fixing bugs, or refactoring. It guides the Red-Green-Refactor cycle, requiring test creation before any code and user approval of test cases. Integrated with pytest, ruff, and mypy for testing and code quality.

Sby Skills Guide Bot
DevelopmentIntermediate
6/2/2026
Claude Code
#tdd#test-driven-development#workflow#test-first#pytest

Recommended for

Automated summary

This skill enforces a test-first development workflow by guiding the user through the Red-Green-Refactor cycle, ensuring tests are written before implementation.

Strengths

  • Enforces test discipline leading to higher code quality
  • Catches bugs early by requiring tests before code
  • Clear phases with automatic checks and user approvals
  • Integrates quality tools (ruff, mypy) for code validation

Limitations

  • Assumes user familiarity with TDD principles
  • May slow down development if applied too rigidly
  • Requires pytest and uv setup in the environment
When to use it

Use this skill when starting a new feature, fixing a bug, or refactoring in a Python project that follows structured testing.

When not to use it

Avoid using it for quick prototyping or trivial changes where tests would not provide immediate value.

Security analysis

Safe
Quality score90/100

The skill only uses Bash to run standard development tools (pytest, ruff, mypy) for TDD. No destructive or exfiltrating commands.

No concerns found

How this analysis is made

Examples

Implement a login function using TDD
I need to implement a login function for my authentication module. Please follow the TDD workflow: start by writing a failing test, then implement the minimal code to pass it, and finally refactor.
Add user registration with Red-Green-Refactor
Add a new registration endpoint to the API. Use test-first approach: create tests for success and error cases, then implement the endpoint, and clean up the code.
Fix authentication bug using TDD
There is a bug in the session handling when the token expires. Please use the TDD skill to write a failing reproduction test first, then fix the bug and refactor.

name: tdd-workflow description: TDDワークフローを強制し、テストファースト開発を支援します。新機能実装時に自動起動し、Red-Green-Refactorサイクルを確実に実行します。 allowed-tools: Read Edit Write Glob Grep Bash

TDD Workflow スキル

このスキルは、Constitution Article 1: Test-First Imperative を強制し、テスト駆動開発(TDD)ワークフローを支援します。

起動条件

以下の状況で自動起動します:

  1. 新機能実装開始時: 新しい機能の実装を開始する際
  2. バグ修正開始時: バグを修正する際(再現テストを先に作成)
  3. リファクタリング開始時: 既存コードの改善前にテストを確認

TDDサイクル

Phase 1: Red(テスト作成・失敗確認)

目的: 失敗するテストを先に作成する

  1. テストファイルの作成/特定

    • ファイル命名規則: test_<機能名>.py
    • 配置場所: tests/ ディレクトリ
  2. テストケースの設計

    • 期待する動作を明確に定義
    • エッジケースを考慮
    • 失敗する理由を明確に
  3. テストの実行と失敗確認

    uv run pytest tests/test_<機能名>.py -v
    
  4. ユーザー承認

    • テストケースをユーザーに提示
    • 承認を得てから次のフェーズへ

Phase 2: Green(最小限の実装)

目的: テストを通過する最小限のコードを実装する

  1. 実装ファイルの作成

    • テストを通過させることのみに集中
    • 過剰な設計を避ける
  2. テストの実行と成功確認

    uv run pytest tests/test_<機能名>.py -v
    
  3. 品質チェック

    uv run ruff check --fix . && uv run ruff format . && uv run mypy .
    

Phase 3: Refactor(リファクタリング)

目的: テストを維持しながらコードを改善する

  1. コードの改善

    • 重複の除去
    • 可読性の向上
    • パフォーマンスの最適化
  2. テストの再実行

    uv run pytest tests/test_<機能名>.py -v
    
  3. 全テストの確認

    uv run pytest
    

テスト構成の原則

ファイル対応

| 実装ファイル | テストファイル | |-------------|--------------| | src/auth.py | tests/test_auth.py | | src/article.py | tests/test_article.py | | src/session.py | tests/test_session.py |

テストクラス構成

# tests/test_auth.py
import pytest

class TestLogin:
    """ログイン機能のテスト"""

    def test_login_success(self) -> None:
        """正常なログインが成功すること"""
        ...

    def test_login_invalid_credentials(self) -> None:
        """無効な認証情報でエラーになること"""
        ...


class TestLogout:
    """ログアウト機能のテスト"""

    def test_logout_success(self) -> None:
        """正常なログアウトが成功すること"""
        ...

テスト命名規則

  • test_<機能>_<状況>_<期待結果>
  • 例: test_login_with_valid_credentials_returns_session

ワークフロー例

例1: 新しいログイン機能の実装

Step 1: テスト作成(Red)

# tests/test_auth.py
import pytest
from src.auth import login

class TestLogin:
    def test_login_success(self) -> None:
        """正常なログインが成功すること"""
        result = login("valid_user", "valid_password")
        assert result.success is True
        assert result.session_id is not None

    def test_login_invalid_password(self) -> None:
        """無効なパスワードでエラーになること"""
        with pytest.raises(AuthenticationError):
            login("valid_user", "wrong_password")

Step 2: テスト失敗確認

uv run pytest tests/test_auth.py -v
# FAILED - ImportError: cannot import name 'login' from 'src.auth'

Step 3: ユーザー承認

「このテストケースで進めてよろしいですか?」

Step 4: 最小実装(Green)

# src/auth.py
from dataclasses import dataclass

@dataclass
class LoginResult:
    success: bool
    session_id: str | None

class AuthenticationError(Exception):
    pass

def login(username: str, password: str) -> LoginResult:
    if password == "wrong_password":
        raise AuthenticationError("Invalid credentials")
    return LoginResult(success=True, session_id="session_123")

Step 5: テスト成功確認

uv run pytest tests/test_auth.py -v
# PASSED

Step 6: リファクタリング(Refactor)

必要に応じてコードを改善

注意事項

  • テストなしの実装は禁止: Article 1 は非交渉的原則
  • テストの承認は必須: ユーザー承認なしに実装を進めない
  • テストカバレッジ: 主要なパスとエッジケースをカバー
  • モック使用: 外部依存はモックを使用して単体テストを実現

チェックリスト

実装開始前に確認:

  • [ ] テストファイルが存在するか
  • [ ] テストが失敗状態(Red)であることを確認したか
  • [ ] ユーザーがテストケースを承認したか

実装完了時に確認:

  • [ ] すべてのテストがパス(Green)しているか
  • [ ] 品質チェック(ruff, mypy)がパスしているか
  • [ ] 不要なコードがないか(リファクタリング完了)

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/tdd-workflow-mm5t8a71/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/tdd-workflow-mm5t8a71' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/tdd-workflow-mm5t8a71/download' --output '.skill-downloads/tdd-workflow-mm5t8a71/SKILL.md.part' && mv '.skill-downloads/tdd-workflow-mm5t8a71/SKILL.md.part' '.skill-downloads/tdd-workflow-mm5t8a71/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

Tools declared by the author (check availability in your agent): Read Edit Write Glob Grep Bash

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/tdd-workflow-mm5t8a71/SKILL.md' && test -s '.skill-downloads/tdd-workflow-mm5t8a71/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/tdd-workflow' && cp -R '.skill-downloads/tdd-workflow-mm5t8a71' '.claude/skills/tdd-workflow'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/tdd-workflow-mm5t8a71'

openskills read 'tdd-workflow-mm5t8a71'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/tdd-workflow-mm5t8a71/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills