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 GitHubysyecust/everything-claude-code
everything-claude-code
skills/tdd-workflow/SKILL.md
January 25, 2026
Select agents to install to:
npx add-skill https://github.com/ysyecust/everything-claude-code/blob/main/skills/tdd-workflow/SKILL.md -a claude-code --skill tdd-workflowInstallation paths:
.claude/skills/tdd-workflow/# 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_