Skip to content

HarshitBamotra/cpp-unit-test-generator

Repository files navigation

C++ Unit Test Generator

Overview

Automatically generate, run, and evaluate Google Test unit tests for your C++ codebase using Github Models

Use these models for best results


Features

  • Scans and parses your C++ codebase
  • Uses a Github Hosted LLM to generate unit tests
  • Builds the project using CMake
  • Resolves build issues using LLM
  • Compiles and runs Google Test test cases
  • Measures test coverage with gcov
  • Removes failing test cases automatically via LLM feedback

Project Structure

unit-test-generator
├── codebase    => C++ source files to test
├── tests       => Generated test files (Automatically generated)
├── build       => CMake build output (Automatically Generated)
├── src         => Node.js test generator logic


Requirements

C++ & Build

  • g++
  • CMake >= 3.10
  • Google Test gtest

Node.js

  • Node.js >= 16
  • js-yaml, glob, dotenv, etc. (run npm install)

Installation and Setup

1. Create a folder and go inside it

mkdir unit-test-generator
cd unit-test-generator

2. Make codebase directory

mkdir codebase

3. Copy your C++ project into codebase folder

mv <path to your c++ project> ./codebase

4. Clone the repository as src:

git clone https://github.com/HarshitBamotra/cpp-unit-test-generator.git src

5. Change directory

cd src

6. Install Dependencies

npm install

7. Set up environment variables

Sample .env file

ENDPOINT = "https://models.github.ai/inference"
MODEL_NAME = "openai/gpt-4.1-mini"
LLM_ACCESS_TOKEN = <your github PAT token> (make sure to provide read access to models while generating PAT token)

8. Start the Application

npm start

Screenshots

Test Generation

Test Generation

Building Project And Fixing Build Errors

Building image and fixing build errors

Removing Failing Test Cases

Removing failing testcases

Test Results

Test results

Test Report

Test report


TODO

  1. Make app run for generalized cpp project path (currently only works for ../codebase)
  2. Make this into a CLI
  3. Add more language generators

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published