Framework for software testing using gtest and gcov tools in Windows + CMake + MinGW64 environment, placing the project files and test cases in the corresponding paths for testing.
- Use the latest version of GCC (I used 14.2; version 8.1 on Windows with MinGW had multithreading issues, which were resolved after upgrading).
- Python.
Run the batch script directly.
- When compiling gtest and gmock with GCC, the local Windows MinGW version 8.1 has multithreading issues. Upgrading to a newer version resolves this problem.
- Code coverage uses the gcov+gcovr toolchain. Gcov is part of GCC, while gcovr requires Python. Set up the environment variables, and after installing the gcovr library via
pip install gcovr
, you can follow the usage instructions.
-
build:Saves the compiled files. The executable and redirected test results (test_reports.txt) are found in
build\bin
. The build folder is automatically generated when running the batch script; it will be deleted and recreated upon rerunning. -
coverage:Stores the generated HTML file for code coverage tests after execution.
-
include:Contains the necessary headers for
src\funcs
andsrc\tests
. -
lib:Contains the static link libraries for gtest and gmock.
-
src:Project folder i. funcs:Contains files for each test function module.
ii. main
iii. tests:Stores headers and test cases. gmock:Contains gmock-r:Stores headers and test cases. gmock:Contains gtest-related headers.
-
build_gcovr.bat:Executes coverage tests upon running.
-
build_test.bat:Runs without executing coverage tests.
- In
src\main\CMakeLists.txt
, set the executable filename on line 17. - Set the corresponding executable filename on line 7 in the batch script.
- When debugging with VSCode: Update the
program
path inlaunch.json
to the executable file path and adjustmiDebuggerPath
to the MinGW path; changecommand
intasks.json
to the MinGW path. - For terminal step-by-step execution: In the build folder, run
cmake .. -G "MinGW Makefiles" -D ENABLE_COVERAGE=ON
;mingw32-make
; after executing the executable, generate.gcda
and.gcno
files, move them to the source file directory; rungcov
to generate.gcov
files; usegcovr -r . --html --html-details -o coverage.html
to generate the coverage HTML file. - In the launch.json , set
args
to--gtest_break_on_failure
to break on failure during gtest debugging.