# cpp-testing > Generalized C++ project testing skill. Analyze project structure, identify key functions, and write test code based on project intent. Use this skill when users need to add unit tests, verify key functions, perform regression testing, check protocol parsers, or test network modules for C++ projects. Supports GoogleTest and Catch2 frameworks. - Author: UnableToCode - Repository: AbleToCode/cpp-testing - Version: 20260207134913 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-07 - Source: https://github.com/AbleToCode/cpp-testing - Web: https://mule.run/skillshub/@@AbleToCode/cpp-testing~cpp-testing:20260207134913 --- --- name: cpp-testing description: Generalized C++ project testing skill. Analyze project structure, identify key functions, and write test code based on project intent. Use this skill when users need to add unit tests, verify key functions, perform regression testing, check protocol parsers, or test network modules for C++ projects. Supports GoogleTest and Catch2 frameworks. --- # C++ Testing Skill Analyze C++ project structure, identify key functions, and generate targeted test code. ## Workflow ``` 1. Analyze Project → 2. Categorize Functions → 3. Test Strategy → 4. Generate Tests → 5. Verify Execution ``` --- ## Phase 1: Project Analysis Scan the following content to build a project model: | File/Directory | Information to Extract | |-----------|----------| | `CMakeLists.txt` | Build targets, dependencies, compile options | | `include/` | Public API, class definitions, function signatures | | `src/` | Implementation details, internal functions | | `README.md` / `doc/` | Project intent, design goals | **Output**: Module list + Dependencies --- ## Phase 2: Function Categorization Categorize functions by test priority: | Priority | Category | Features | Test Focus | |--------|------|------|----------| | **P0** | Protocol/Parsing | `parse`, `decode`, `serialize` | Boundary values, abnormal inputs, endianness | | **P1** | Core Business | State machine, session management | State transitions, concurrency safety | | **P2** | Network I/O | `send`, `receive`, callbacks | Mocking, integration testing | | **P3** | Utilities | Config, logging, conversion | Boundary conditions | Run `scripts/find_key_functions.py` for automated identification. --- ## Phase 3: Test Strategy ### Framework Selection | Scenario | Recommended Framework | Reason | |------|----------|------| | Existing GoogleTest | GoogleTest | Maintain consistency | | New Project | Catch2 | Single header, BDD style | | Need Mocking | GoogleMock | Integrated with GoogleTest | ### Test Patterns Refer to [test_patterns.md](references/test_patterns.md): - Boundary value testing - Abnormal input testing - State machine testing - Asynchronous code testing --- ## Phase 4: Test Generation ### File Naming Convention ``` tests/ ├── test__.cpp ├── mock_.hpp └── fixtures/ └── ``` ### GoogleTest Template ```cpp #include #include ".hpp" class Test : public ::testing::Test { protected: void SetUp() override { /* Initialization */ } void TearDown() override { /* Cleanup */ } }; TEST_F(Test, ) { // Arrange // Act // Assert EXPECT_EQ(expected, actual); } ``` ### Catch2 Template ```cpp #include #include ".hpp" TEST_CASE(" ", "[]") { SECTION("") { // Arrange // Act // Assert REQUIRE(condition); } } ``` --- ## Phase 5: Verify Execution ### Build Tests ```bash cmake -DBUILD_TESTING=ON .. cmake --build . --target all_tests ``` ### Run Tests ```bash ctest --output-on-failure # Or run directly ./tests/ ``` ### Coverage (Optional) ```bash cmake -DCMAKE_CXX_FLAGS="--coverage" .. lcov --capture --directory . --output-file coverage.info genhtml coverage.info --output-directory coverage_report ``` --- ## Quick Commands | Task | Command | |------|------| | Analyze project structure | `python scripts/analyze_project.py ` | | Find key functions | `python scripts/find_key_functions.py ` | --- ## Reference Documents - [Analysis Workflow Details](references/analysis_workflow.md) - [Test Patterns Reference](references/test_patterns.md) - [Function Categorization Guide](references/function_categories.md)