|
| | 🔨 Utility Macros and Types |
| | Type conversions, casting helpers, and common data structures.
|
| | 🎪 Mock Objects |
| | Simulate objects and control function return values in tests.
|
| | ✅ Checking Parameters |
| | Validate function parameters match expected values.
|
| | 🛡️ Assert Macros |
| | Verify conditions and fail tests when assertions don't hold.
|
| | 🔢 Call Ordering |
| | Ensure functions are called in the correct sequence.
|
| | ▶️ Running Tests |
| | Execute test suites with setup and teardown functions.
|
| | 🧩 Dynamic Memory Allocation |
| | Detect memory leaks, buffer overflows, and allocation errors.
|
| | 🎯 Standard Assertions |
| | Test code that uses assert(3) from the standard C library.
|
| | 🔧 Configuration and Output |
| | Control test output formats and execution behavior.
|
| | 📌 Version Information |
| | Query cmocka library version at compile time and runtime.
|
Unit testing framework for C with support for mock objects.
cmocka is an elegant unit testing framework for C with support for mock objects. It only requires the standard C library, works on a lot of platforms (including embedded) and with different compilers.
Standard includes
CMocka requires the include of the following list of standard headers or their equivalent.
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
The header file 'cmocka.h' includes those headers already and in case your platform does not provide those header files, you must #define CMOCKA_NO_STANDARD_INCLUDES in order to prevent the include of those files.
An example of how your code which uses CMocka could look like is given below.
#include "path/to/cmocka_platform.h"
#define CMOCKA_NO_STANDARD_INCLUDES
#include <cmocka.h>