CheckOps home

Tools directory

C

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.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

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

  1. Mock objects: will_return and mock().
  2. Assertions: Integers, strings, pointers.
  3. Group tests: Setup and teardown.
  4. Output formats: TAP, subunit, xUnit.
  5. Standard C only: Few dependencies.
  6. Cross-platform: Including embedded.

Pros

  1. Free to use: Open source under Apache-2.0.
  2. Lightweight: Easy to port.

Cons

  1. Manual mocks: Mocks are hand-written with wrap.
  2. C only: No C++ niceties.
  3. Docs style: API reference heavy.
#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.

  1. 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.