Skip to content
/ c-test Public

Quick start sample for testing C code with GoogleTest

Notifications You must be signed in to change notification settings

jjaine/c-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Testing C code with GoogleTest

A sample project about testing C code with GoogleTest. Used the Quickstart guide for building with CMake as a reference.

Prerequisites

  • CMake (for macOS install from Homebrew with brew install cmake)
  • C compiler (for macOS included with Xcode)

How-to

  1. Make build directory with mkdir build.
  2. Build the main and tests with
cmake -S . -B build
cmake --build build
  1. Go into the build directory with cd build.
    • Run main with ./main.
    • Run tests with ctest.

C programming 101

  • main.c for the main function
  • source.h for defining interfaces (name as you wish)
  • source.c for implementing the functions

Testing

  • 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

About

Quick start sample for testing C code with GoogleTest

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published