CheckOps
cmocka
cmocka is an Apache-2.0 unit testing framework for C with mock objects that needs only the standard C library, working across platforms including embedded.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
cmocka is an elegant unit testing framework for C with support for mock objects. It only requires the standard C library and works on a range of platforms, including embedded, and with different compilers.
Tests are functions registered with cmocka_unit_test and run with cmocka_run_group_tests. Assertions such as assert_int_equal and assert_non_null check results, and mocks use will_return with mock() or mock_type to supply values. Output formats include TAP, subunit and xUnit XML.
The project is hosted on GitLab, with commits as recent as February 2026.
Running cmocka tests on the host compiler in CI gives fast feedback before slower on-target runs.
Its small footprint suits constrained targets.
Its long history makes it a stable foundation.
Features
- Mock objects: will_return and mock().
- Assertions: Integers, strings, pointers.
- Group tests: Setup and teardown.
- Output formats: TAP, subunit, xUnit.
- Standard C only: Few dependencies.
- Cross-platform: Including embedded.
Pros
- Free to use: Open source under Apache-2.0.
- Lightweight: Easy to port.
Cons
- Manual mocks: Mocks are hand-written with wrap.
- C only: No C++ niceties.
- Docs style: API reference heavy.
Usage and Links (Example)
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
static void test_add(void **state) { assert_int_equal(add(2, 3), 5); }
int main(void) {
const struct CMUnitTest tests[] = { cmocka_unit_test(test_add) };
return cmocka_run_group_tests(tests, NULL, NULL);
}
Resources:
Pricing
cmocka is free and open source under the Apache-2.0 licence.
Recommended for?
- C developers needing a portable test framework with mocks.
Conclusion
cmocka is a lean, proven choice for C unit tests.
Use linker wrapping for mocks of external functions.
On CheckOps, cmocka is filed under the Unit testing stage. Related tools listed here include Renode, Ceedling, Unity Test (C), labgrid, pytest-embedded and Wokwi. Which one fits best depends mostly on your stack, your team’s size and skills, and whether you prefer to run tools yourself or pay for a managed service. This page reflects the official website, documentation and repository as they stood on 11 November 2026.
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with cmocka side by side.
RRenodeRenode is Antmicro's MIT-licensed open-source simulation framework that runs unmodified embedded firmware on virtual boards and multi-node networks, with Robot Framework-based testing for CI.Compare with cmocka
CCeedlingCeedling is an MIT build and test system for C projects from ThrowTheSwitch, combining Unity, CMock and CException for embedded unit testing.Compare with cmocka
UUnity Test (C)Unity is an MIT-licensed unit testing framework for C focused on embedded toolchains, consisting of a single C file and two headers, from ThrowTheSwitch.org alongside CMock and Ceedling.Compare with cmocka
Llabgridlabgrid is an LGPL-2.1-or-later Python library from Pengutronix for controlling embedded boards in automated tests, with remote access, power and boot control, and a pytest plugin.Compare with cmocka
Ppytest-embeddedpytest-embedded is Espressif's MIT pytest plugin for embedded testing, with services for serial, ESP-IDF, Arduino, QEMU, Wokwi and JTAG.Compare with cmocka
WWokwiWokwi is an online and VS Code simulator for ESP32, Arduino, STM32 and other microcontrollers, with Wokwi CI for automated firmware tests in GitHub Actions and GitLab CI.Compare with cmocka