C Test Generator – Boundary Value Analysis (v2.0.0)
A VS Code extension that automatically generates Google Test (GTest) test cases for your C functions using Boundary Value Analysis (BVA).
Right-click any C function → get a full set of boundary tests instantly. No test-writing boilerplate.
✨ Features
- One-click test generation — Place your cursor inside any C function and press
Ctrl+Shift+T (or right-click → Generate Tests for This Function)
- Boundary Value Analysis — Automatically generates test cases for
INT_MIN, INT_MAX, 0, boundary ±1 values, float/double infinities, and more
- Supports all C primitive types —
int, unsigned int, long, short, float, double, char, size_t, and their variants
- Pointer, array & struct support — Generates
NULL / valid-pointer tests, single-element / typical array tests, and zero-initialized / extreme struct tests
- Global variable awareness — Detects and tests global variables used by your function
- Test density control — Choose
minimal, standard, or exhaustive via the cTestGenerator.testDensity setting
- Interactive expected values — Fill in expected results through a built-in webview UI, or skip and fill them manually later
- Custom Tests tab — Add your own test cases with custom parameter values; struct parameters get per-field inputs; remove any custom test with the ✖ button
- Preview tab — See the full generated C++ test code with syntax highlighting before saving
- Test checkboxes — Select/deselect individual test cases before saving; unchecked tests are commented out
- CMake integration — Automatically generates
CMakeLists.txt alongside your tests
- Build & Run — Build and execute tests directly from VS Code with one click
- VS Code Problems panel — Build errors from g++/cmake are parsed and shown with file/line info
- Output Channel logging — All extension activity appears in the "C Test Generator" output panel
- Cross-platform — Works on Windows, Linux, and WSL
🆕 What's New in v2.0.0
Goal 1 — Pointer, Array & Struct support
// All of these parameter types are now fully supported:
int func_with_ptr(int *ptr); // pointer: NULL + valid-ptr tests
int func_with_arr(int arr[], int size); // array: single-element + typical
int func_with_struct(struct Point p); // struct: zero-init + extreme values
Goal 2 — Smarter Boundary Values
float / double — now tests +∞, −∞, FLT_EPSILON, DBL_EPSILON
char — adds '\0' (null terminator) and 'A' (printable) boundary classes
size_t — boundaries 0, 1, 10, SIZE_MAX
- Correct assertion macros:
EXPECT_FLOAT_EQ / EXPECT_DOUBLE_EQ for floating-point returns
Goal 3 — Test Density Configuration
Add to your VS Code settings.json or workspace settings:
{
"cTestGenerator.testDensity": "standard"
}
| Value |
Tests per parameter |
Description |
minimal |
min, max, zero |
Fewest tests |
standard |
min, min+1, max-1, max |
Default — full BVA |
exhaustive |
all boundary classes |
Includes infinities, near-zero, overflow |
Goal 4 — UI Improvements
- 3-tab webview — Boundary Tests, Custom Tests, and Preview tabs
- Preview tab in the webview with syntax-highlighted generated code
- Checkboxes to include/exclude individual tests before saving
- Stats bar — "Tests generated / Selected / Custom"
Goal 5 — Better Error Reporting
- Build errors appear in the Problems panel (clickable, with file + line)
- "C Test Generator" Output Channel for all log messages
- Clearer error: "Place your cursor inside a C function body and try again."
📋 Prerequisites
The extension itself installs with zero dependencies — just install and go. However, to build and run the generated tests, your system needs:
Required
| Tool |
Why |
Install |
| C/C++ Compiler (gcc/g++) |
Compiles the generated test files |
See below |
| CMake (≥ 3.14) |
Builds the test project |
See below |
| Google Test (GTest) |
The testing framework used by generated tests |
See below |
Installation by OS
🐧 Ubuntu / Debian (including WSL)
sudo apt update
sudo apt install -y build-essential cmake libgtest-dev
# Build and install GTest (required on Ubuntu)
cd /usr/src/gtest
sudo cmake .
sudo make
sudo cp lib/*.a /usr/lib/
🍎 macOS
brew install cmake googletest
🪟 Windows (with WSL — recommended)
- Install WSL:
wsl --install
- Inside WSL, follow the Ubuntu instructions above
- Open your project in VS Code with the Remote - WSL extension
✅ Verify your setup
Open a terminal and run:
g++ --version # Should print version info
cmake --version # Should print 3.14 or higher
If both commands work, you're ready to go.
🚀 Installation
From the VS Code Marketplace (Recommended)
- Open VS Code
- Go to the Extensions sidebar (
Ctrl+Shift+X)
- Search for "Random Test Data Generation" in the search bar
- Click Install on the extension by S5in
- You're ready to go — no reload needed!
Tip: You can also open the Command Palette (Ctrl+Shift+P), type ext install S5in.random-test-data-generation, and press Enter.
From the terminal
code --install-extension S5in.random-test-data-generation
📖 How to Use
Step 1: Open a C file
Open any .c file in VS Code.
Step 2: Generate tests
Place your cursor inside a function and do one of:
- Press
Ctrl+Shift+T (Cmd+Shift+T on Mac)
- Right-click → "Generate Tests for This Function"
- Command Palette (
Ctrl+Shift+P) → "C Test Generator: Generate Tests for This Function"
Step 3: The extension creates two files next to your .c file
your_project/
├── math.c ← your source file
├── add_test.cpp ← generated test file (for function "add")
├── CMakeLists.txt ← generated build configuration
└── build/ ← created when you build
└── add_tests ← compiled test executable
Step 4: Fill expected values & customize tests
After generation, a popup offers three choices:
- Fill Expected Values — Opens the full webview panel (see below)
- Build & Run — Skips the webview and immediately builds and runs the tests
- View Tests — Opens the generated test file directly in the editor
Choosing Fill Expected Values opens a rich webview panel with three tabs:
- 🧪 Boundary Tests — All auto-generated test cases displayed as cards. Each card shows the test name, read-only input values, and an Expected result field. Use the checkbox on each card to include or exclude it, or toggle Select/Deselect All at the top.
- Enter a numeric value (e.g.,
42, -100, 0.5)
- For
float/double returns, use INFINITY, NAN, or exact values like 1.5f
- Leave blank to keep the
FAIL() placeholder and fill in manually later
- ➕ Custom Tests — Add your own test cases with custom parameter values and expected results. Struct parameters get per-field inputs. Remove any custom test with the ✖ button.
- 👁️ Preview — See the full generated C++ test file with syntax highlighting before saving.
A stats bar at the top tracks: Tests generated / Selected / Custom.
When you're ready, click one of three buttons:
| Button | What it does |
|--------|--------------|
| 🚀 Save & Build & Run | Save all expected values and custom tests, then immediately build and run |
| 💾 Save Only | Save changes without building |
| ⏭️ Skip | Close the panel without saving (tests keep FAIL() placeholders) |
Step 5: Build & Run
Build and run can happen automatically (from the popup or webview), or you can trigger it manually at any time:
- Command Palette (
Ctrl+Shift+P) → "C Test Generator: Build & Run Tests"
The "C Test Generator" output channel shows the full build log and test results. Any build errors are also surfaced in the VS Code Problems panel with clickable file + line info.
🧪 Example
Given this C function:
int add(int x, int y) {
return x + y;
}
The extension generates tests like:
TEST(addTest, Baseline_AllZero) {
// Arrange
int x = 0;
int y = 0;
// Act
int result = add(x, y);
// Assert
// TODO: Provide expected value
FAIL() << "Expected value needed. Got: " << result;
}
TEST(addTest, Param_x_Min) {
// Arrange
int x = INT_MIN;
int y = 0;
// Act
int result = add(x, y);
// ...
}
Example with a pointer parameter:
// For: int deref(int *ptr)
TEST(derefTest, Param_ptr_NullPointer) {
int *ptr = NULL;
int result = deref(ptr);
// ...
}
TEST(derefTest, Param_ptr_ValidPointer) {
int ptr_val = 0;
int *ptr = &ptr_val;
int result = deref(ptr);
// ...
}
⌨️ Commands
| Command | Shortcut | Description |
|---------|----------|-------------|
| Generate Tests for This Function | Ctrl+Shift+T | Generate boundary tests for the function at cursor |
| Build & Run Tests | — | Build and execute the generated tests |
| Clean Build Directory | — | Remove the build/ directory |
⚙️ Configuration
| Setting | Default | Options | Description |
|---------|---------|---------|-------------|
| cTestGenerator.testDensity | standard | minimal, standard, exhaustive | Controls how many boundary test cases are generated per function |
⚠️ Important Notes
- One function at a time — Place your cursor inside the function you want to test. The extension tests the function at the cursor position, not the entire file.
- C files only — The extension activates only for
.c files. It generates .cpp test files (Google Test is C++).
- CMakeLists.txt is overwritten — Each time you generate tests, the
CMakeLists.txt in that directory is regenerated. If you've customized it, back it up first.
- Functions with 7+ parameters — The extension will warn you about large parameter counts (exponential test combinations). Consider refactoring to use structs.
📦 Release Notes
2.0.0 — Iteration 2
- Pointer, array & struct parameter support
- Smarter boundary values (
size_t, char null/printable, float/double infinity, overflow)
- Test density configuration setting (
minimal / standard / exhaustive)
- Custom Tests tab — add your own test cases with per-field struct inputs
- Preview tab with syntax highlighting in webview
- Checkboxes to include/exclude tests before saving
- 3-choice notification popup (Fill Expected Values / Build & Run / View Tests)
- VS Code Problems panel integration for build errors
- Output Channel logging
- Fixed assertion macros for float/double return types
1.0.0 — Iteration 1
- Initial release
- Boundary value analysis for all C primitive types
- Google Test code generation with
CMakeLists.txt
- Interactive expected value webview
- Build & Run integration
- Windows, Linux, and WSL support
📝 License
University project — 3rd year.