cpp-testing
Skill0 starsChanged 51 days agoMITView on GitHub
Test-driven development and unit testing for modern C++ using GoogleTest, GoogleMock, and CMake CTest. Covers test layout, fixture lifecycle, fakes versus mocks, parameterized tests, test discovery, and sanitizer configurations (ASan, UBSan, TSan). Use when writing, updating, or fixing C++ tests, configuring CTest or GoogleTest, investigating flaky test behavior, or setting up memory sanitizers for C++ test suites.
18 other projects use a version of this.
Adopted by
Most recently taken up by
- Rojios/everything-claude-codetheir own version, first seen Nov 8, 2026
- majay123/my-embedded-skillstheir own version, first seen Nov 8, 2026
- TsinHzl/claude-code-configtheir own version, first seen Nov 1, 2026
- ghvinashvili/specagenttheir own version, first seen Nov 1, 2026
- renepf/claude-skillstheir own version, first seen Oct 25, 2026
- davidanthonyn/claude-skillstheir own version, first seen Oct 20, 2026
Other versions18 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 18
- loulanyue/awesome-claude-notes★ 272same name
- Fmarzochi/EGC★ 61same name
- gongyijie85/dsh-ecc★ 8same name
- majay123/my-embedded-skills★ 8same name
- ghvinashvili/specagent★ 7same name
- ronmkr/PromptBook★ 2same name
- TsinHzl/claude-code-config★ 2same name
- junimnjw/everything-claude-code★ 1same name
- Rojios/everything-claude-code★ 1same name
- Ronnasayd/aipp★ 1same name
8 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository10 other files it gives its agents.
- cpp-coding-standardsSkill
- embedded-firmware-misraSkill
- latency-critical-systemsSkill
- m5-onboardSkill
- onnx-quantize-tflmSkill
- openlane-sky130-flowSkill
- rtl-testbench-disciplineSkill
- rtl-verilog-lintSkill
- skill-eval-harnessSkill
- timing-closure-cdcSkill
The file
We split this skill into the rules it gives an agent
7 rules. 0 are common, 4 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 17 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 20
Red-Green-Refactor loop: Write the failing assertion first, implement the minimum code to turn it green, then refactor with test …
- Distinctive: line 21
Isolation over integration: Prefer fakes and explicit dependency injection rather than relying on shared global state.
- Very specific: line 22
Structured directory layout: Keep tests mirrored against source under tests/unit/, tests/integration/, and tests/fixtures/.
- Very specific: line 23
Dynamic discovery: Use gtest_discover_tests() in CMake so CTest registers tests automatically without manual listing.
- Very specific: line 27
Prefer EXPECT_* for non-fatal checks that allow remaining assertions in the test to execute, and ASSERT_* when failure invalidates …
- Distinctive: line 42
When verifying mocked interactions with GoogleMock:
- Distinctive: line 54
Run tests under sanitizers by enabling compiler flags during configuration:
“Common” is measured: kept by at least 6 in 10 of the 17 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
C++ Testing with GoogleTest and CTest
Flaky tests, silent memory corruption in test fixtures, and slow test discovery degrade confidence in test suites. Establishing a deterministic test harness with fast discovery and active sanitizers catches memory leaks and race conditions before code merges.
ctest --test-dir build --output-on-failure -j4Detailed test fixture syntax, parameterized test suites, and CMake integration patterns are documented in references/gtest-patterns.md.
Core Concepts
- Red-Green-Refactor loop: Write the failing assertion first, implement the minimum code to turn it green, then refactor with test verification.
- Isolation over integration: Prefer fakes and explicit dependency injection rather than relying on shared global state.
- Structured directory layout: Keep tests mirrored against source under
tests/unit/,tests/integration/, andtests/fixtures/. - Dynamic discovery: Use
gtest_discover_tests()in CMake so CTest registers tests automatically without manual listing.
Writing Deterministic Tests
Prefer EXPECT_* for non-fatal checks that allow remaining assertions in the test to execute, and ASSERT_* when failure invalidates subsequent logic (such as checking pointer nullity before dereferencing).
#include <gtest/gtest.h>
TEST(RingBufferTest, OverwriteAdvancesTail) {
RingBuffer<int, 4> buffer;
for (int i = 0; i < 5; ++i) {
buffer.push(i);
}
EXPECT_EQ(buffer.size(), 4u);
EXPECT_EQ(buffer.pop(), 1);
}When verifying mocked interactions with GoogleMock:
class MockHardwareBus : public HardwareBus {
public:
MOCK_METHOD(bool, WriteRegister, (uint16_t reg, uint8_t val), (override));
MOCK_METHOD(uint8_t, ReadRegister, (uint16_t reg), (override));
};Diagnosing Memory and Concurrency Bugs
Run tests under sanitizers by enabling compiler flags during configuration:
- AddressSanitizer (
-fsanitize=address): Catches out-of-bounds accesses, use-after-free, and stack corruption. - UndefinedBehaviorSanitizer (
-fsanitize=undefined): Catches integer overflows, null pointer dereferences, and alignment violations. - ThreadSanitizer (
-fsanitize=thread): Detects data races in multithreaded test cases. Do not combine TSan with ASan in the same binary.
Honest limits
Unit tests demonstrate the presence of specific verified behaviors, but cannot prove the absence of subtle hardware interactions, cache coherency anomalies, or platform-specific driver timing errors. Sanitizers introduce CPU and memory overhead, meaning timing-sensitive bugs in real-time loops may not manifest during sanitized test runs.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

