ihct
(I Hate C Testing)
|
Olle Lögdahl, 13 December 2020
ihct is a minimal C unit-testing framework. Intended for light unit testing, and focusing on development speed. Looking for more features, so please give any suggestions.
To use this framework, simply include ihct.h
in your project and link to the library. Everything else happens automatically. The following code should get you started.
To fully install the library, run:
See ex.c
for an extended example. Note that tests are created as it's own executable, and therefore needs an entrypoint. The example ex.c
can be compiled and executed by running:
I have for a long time been stuck at unit testing in plain C. Many modern solutions use C++ as a test environment for C, but I wanted something more lightweight, that i can quickly get up to speed with. I decided to write my own test framework with two things in mind: development speed and minimalism. To improve development speed, all test functions are automatically included into the runner, and the library interface is kept minimal. It requires no dependencies other than a POSIX compliant OS, and compiles on all GNU C99 POSIX compatible compilers. The library also implements some safety to tests, catching fatal signals and hung functions.
Self tests can be run along with own tests by adding compiler flag -DIHCT_SELF_TEST
. (This may be very redundant; just see it as more examples :-) )
all macros (IHCT_TEST
, IHCT_ASSERT
etc.) can be shortened to remove the IHCT
prefix, by defining IHCT_SHORT
before including the header file.
__attribute__((constructor))
it is not compilable with MSVC.This project, and all code it contains, is licensed under the MIT License and can be read [here](LICENSE).