A dead-simple, yet extensible, C and C++ unit testing framework.
Most test frameworks for C require a lot of boilerplate code to set up tests and test suites -- you need to create a main, then register new test suites, then register the tests within these suits, and finally call the right functions.
This gives the user great control, at the unfortunate cost of simplicity.
Criterion follows the KISS principle, while keeping the control the user would have with other frameworks:
- C99 and C++11 compatible.
- Tests are automatically registered when declared.
- Implements a xUnit framework structure.
- A default entry point is provided, no need to declare a main unless you want to do special handling.
- Test are isolated in their own process, crashes and signals can be reported and tested.
- Unified interface between C and C++: include the criterion header and it just works.
- Supports parameterized tests and theories.
- Progress and statistics can be followed in real time with report hooks.
- TAP output format can be enabled with an option.
- Runs on Linux, FreeBSD, Mac OS X, and Windows (Compiling with MinGW GCC and Visual Studio 2015+).
If you have a different platform, you can still build the library from source
An online documentation is available on ReadTheDocs (PDF | Zip | Epub)
Sample tests can be found in the sample directory.
- A simple test
- Using multiple suites
- Writing assertions
- Adding test fixtures
- Tests with signals
- Using report hooks
Q. What's wrong with other C test frameworks?
A. I worked with CUnit and Check, and I must say that they do their job
very well -- the only thing that bugs me is that setting up a test
suite from scratch is a pain, it should really be simpler. Most
(if not all) high-level languages have test frameworks with automatic
test registration, but all the ones for C require you to set up a
main, manually register suites, then tests. Criterion tries to
fix these shortcomings.
Q. Where has this been tested?
A. Currently, on Linux 2.6.32 and Linux 3.15.7, although it should work on
most *nix systems; Mac OS X Yosemite 10.10, FreeBSD 10.0, Windows 7 and 2K.
Logo done by Greehm