libcester logo

libcester

A robust header only unit testing framework for C and C++ programming language.
Support function mocking, memory leak detection, crash report. Works on various platorms including embedded
systems and compatible with various compilers. Requires no dependency only the header file is needed to get the tests running.

Write Once, Test Anywhere

libcester is compliant with the original C language specification ISO/IEC 9899:1990 and the first POSIX specification IEEE Std 1003.1-1988 which ensures the project compatibility in various environments including embedded systems.

It also makes use of features in the newer revisions ISO/IEC 9899:1999 and IEEE Std 1003.1-2001 whenever possible.

Automatic Tests Registration

With the stretched use of C preprocessor libcester in most cases does not require you to manually register your test cases, you just define your test with the provided macros and it will be executed.

Supports various output formats

libcester supports various output formats for test analysis. The following output formats are supported:

Detailed documentation

The documentation provides several examples, tutorials, and detailed guides for using the library.

While reference provides a low-level overview of all the implemented APIs in the library

Function mocking

Create functions that simulate the behaviour of the real function implementation.

Mocking function is useful when your unit tests relies on dependencies which are not available at the time of running your tests.

Isolated unit testing

Each test case is run in isolation which allows exceptions like a segfault, premature termination e.t.c to be reported.

A crahsed test case does not cause the testing to stop instead the test case is reported as failure and libcester continue running other test cases.

Shared objects

Each test cases accepts a test_instance variable that can be used to share data across multiple test cases.

There are also CESTER_BEFORE_ALL, CESTER_BEFORE_EACH, CESTER_AFTER_EACH and CESTER_AFTER_ALL macros to setup and tear down shared functions and objects use in the test cases.

Testing of memory leaks

The library detects memory leak in the test cases without the need to run program like valgrind. The precise amount of bytes leaked is reported for each test case.

Memory leak test is optional and can be diabled with the option --cester-nomemtest

MIT License

This allows you to use the library freely in your open or closed source project. You also have the freedom to modify your version so far it provides the freedom MIT License stated.

Intuitive APIs


Cester provides clean macros to write your unit tests. You don't have to worry about test case registration it all taken care of at compile time. Optionally you can manually register specific test cases.

There are various assertion macros available for use in your test.
#include <exotic/cester.h>

CESTER_BEFORE_ALL(test_instance,
    test_instance->arg = (void*) "exoticlibs";
)

CESTER_TEST(test_assert_cmp_msg, test_instance,
    cester_assert_cmp_msg(NULL, ==, ((void*)0), "Check if NULL is same as ((void*)0)");
    cester_assert_cmp_msg(NULL, !=, "String", "is NULL equal to 'String'");
)

CESTER_TEST(test_string, test_instance,
    cester_assert_str_equal((char*)test_instance->arg, "exoticlibs");
    cester_assert_str_not_equal((char*)test_instance->arg, NULL);
)