unitctest is a tiny (~500 LoC for the unitctest header), header-only unit test framework for C (and C++)
Using unitctest is very easy and straightforward, with no need to install anything.
In order to use unitctest, you basically have two options :
- Download the source code of this repository and copy folder include/unitctest in your project;
- Use
git submodule
(branchrelease
presents a cleaner repository)
Once you have downloaded (or added the submodule), include the header in your test C file :
#include <unitctest/unitctest.h>
And you are set. Well, almost. For unitctest to work correctly, you must have the following included at the end of your test file :
TEST_MAIN() // DO NOT add ';' at the end.
This is required, among other things, to create the main
function of the test program.
Therefore, this must appear in only a single test source code for a given test program.
Check examples inside folder test/
.
unitctest is officially supported on the following platforms:
Operating Systems |
---|
Linux |
macOS |
If you run into any problems on your platform, please create an issue, or, even better, send a PR with fixes. ;)
Support for C++ is still under development.
Language | Version |
---|---|
C | C99*, C11, C14, C17 |
C++** | C++1x, C++2x |
*There is a known small issue with logging (related to print type)
** Some caveats :
- Comparisons rely on '==' operator of operands;
- Compiler will signal errors if operand does not have '<<' implemented;
- Currently mixing cerr with fprintf to take advantage of '<<'.
Well, the answer is that I wanted to have a simple framework that I could easily change to fulfill any special need (header-only, small size, etc).
The main difference is that unitctest is smaller and header-only. Thus, no installation is required. Moreover, googletest has more features (and it is heavier, not header-only, ...), as mocking, which we do not support.
mocking is currently out of the scope for unitctest. However, you can use unitctest along with the Fake Function Framework.