A sample project about testing C code with GoogleTest. Used the Quickstart guide for building with CMake as a reference.
- CMake (for macOS install from Homebrew with
brew install cmake
) - C compiler (for macOS included with Xcode)
- Make
build
directory withmkdir build
. - Build the
main
and tests with
cmake -S . -B build
cmake --build build
- Go into the build directory with
cd build
.- Run
main
with./main
. - Run tests with
ctest
.
- Run
main.c
for the main functionsource.h
for defining interfaces (name as you wish)- Remember to use include guards! :)
source.c
for implementing the functions
- Write tests into
test
folder, use.cc
file extension - Modify
CMakeLists.txt
as needed when changing the source and test file names - C source files need to be included inside
extern "C"
. - Assertions list in GoogleTest documentation