Back to Skills

tdd-workflow

verified

Use this skill when writing new features, fixing bugs, or refactoring C++20 code. Enforces test-driven development with Google Test/Mock, CMake/CTest integration, and 80%+ coverage via gcov/lcov.

View on GitHub

Marketplace

everything-claude-code

ysyecust/everything-claude-code

Plugin

everything-claude-code

workflow

Repository

ysyecust/everything-claude-code

skills/tdd-workflow/SKILL.md

Last Verified

January 25, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/ysyecust/everything-claude-code/blob/main/skills/tdd-workflow/SKILL.md -a claude-code --skill tdd-workflow

Installation paths:

Claude
.claude/skills/tdd-workflow/
Powered by add-skill CLI

Instructions

# Test-Driven Development Workflow (C++20)

This skill ensures all C++ code development follows TDD principles with comprehensive test coverage using Google Test and CTest.

## When to Activate

- Writing new features or functionality
- Fixing bugs or issues
- Refactoring existing code
- Adding new classes or algorithms
- Creating new solver components

## Core Principles

### 1. Tests BEFORE Code
ALWAYS write tests first, then implement code to make tests pass.

### 2. Coverage Requirements
- Minimum 80% coverage (unit + integration)
- All edge cases covered
- Error scenarios tested
- Boundary conditions verified

### 3. Test Types

#### Unit Tests (Google Test)
- Individual functions and classes
- Template instantiations
- Algorithm correctness
- Edge cases and error paths

#### Integration Tests (CTest)
- Multi-component interactions
- I/O operations
- MPI communication patterns
- End-to-end solver pipelines

#### Performance Tests
- Scalability benchmarks
- Cache efficiency validation
- Regression detection

## TDD Workflow Steps

### Step 1: Define Interface
```cpp
// include/project/solver/cg_solver.hpp
#pragma once
#include <span>

namespace hpc::solver {

struct CgConfig {
  int max_iter = 1000;
  double tolerance = 1e-10;
};

class CgSolver {
public:
  explicit CgSolver(CgConfig config = {});

  /// @return Number of iterations performed.
  [[nodiscard]] int Solve(std::span<double> x, std::span<const double> b);

  [[nodiscard]] double Residual() const;

private:
  CgConfig config_;
  double residual_ = 0.0;
};

}  // namespace hpc::solver
```

### Step 2: Write Failing Test (RED)
```cpp
// tests/unit/test_cg_solver.cpp
#include <gtest/gtest.h>
#include "project/solver/cg_solver.hpp"

namespace hpc::solver {
namespace {

class CgSolverTest : public ::testing::Test {
protected:
  void SetUp() override {
    // Identity system: solution is b itself
    b_ = {1.0, 2.0, 3.0};
    x_.resize(b_.size(), 0.0);
  }

  std::vector<double> x_;
  std::vector<double> b_

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
6949 chars