ThrowTheSwitch/CMock
FreeMock/stub generator for C
FreeFree tier
About ThrowTheSwitch/CMock
CMock is an open-source mock and stub generator and runtime for unit testing C code. It automatically parses C headers and generates mock interfaces, simplifying the process of isolating code units for testing. Designed to work seamlessly with Unity Test (a lightweight C unit testing framework) and part of the ThrowTheSwitch embedded software testing ecosystem, CMock integrates with Ceedling, a test build manager. It is written in Ruby and distributed as a Ruby gem, with the source code available on GitHub.
Key Features
Automatically parses C headers to generate mock and stub interfaces
Designed to work smoothly with Unity Test framework
Part of the ThrowTheSwitch embedded software testing tools
Integrates with Ceedling test build manager
Open source with MIT license
Provides a runtime for mock/stub behavior in unit tests
Pros & Cons
Pros
- Automates the tedious task of writing mock functions by hand
- Free and open source (MIT license) with active community
- Tight integration with Unity Test and Ceedling streamlines testing
- Well-documented with examples and a summary guide
Cons
- Requires Ruby runtime to run (as a Ruby gem)
- Primarily designed for C, not applicable to other languages
Best For
Unit testing C code in embedded systemsIsolating code units for testing by mocking dependenciesSimplifying test creation for C projects using Unity TestAutomated test generation in continuous integration pipelines
FAQ
How do I install CMock?
You can clone the repository from GitHub using 'git clone --recursive https://github.com/throwtheswitch/cmock.git' or download a zip file. If you are using Ceedling, CMock is included automatically.
How does CMock work?
CMock parses your C header files and automatically generates mock interfaces (source code) that simulate the behavior of the original functions, enabling isolated unit testing.