/c-unit-testing

Example of how to write unit tests in C programming language

Primary LanguageCGNU General Public License v3.0GPL-3.0

C unit testing

Example of how to write unit tests in C using Unity framework.

Project structure

There are three important directories:

  • src - source code
  • test - test cases
  • unity - unity test framework source

The unity directory is added as a submodule. Make sure to initialize it after cloning the project,

$ git submodule init && git submodule update --recursive

The Makefile is the standard Unity make, inspired from here.

Test file names should start with Test* (case sensitive). Each test file should implement the setUp, thetearDown, and the main functions since this project uses the default Unity test runner.

How to run

You need to install make.

To run tests:

$ make test

To compile the code:

$ make compile

To generate an executable:

$ make install

To run all at once:

$ make

To clean:

$ make clean

To format the code:

$ make format # follow Linux style