CppUTest
Freeunit testing and mocking framework for C/C++ with a focus on working for embedded systems!
FreeFree tier
About CppUTest
CppUTest is a C/C++ unit testing and mocking framework based on the xUnit architecture. It supports test-driven development (TDD) and is particularly popular in embedded systems development but works for any C/C++ project. Key design principles include simplicity, portability across old and new platforms, and being built with TDD for TDD developers. It offers multiple installation methods including package managers (apt-get, Homebrew) and source builds with support for MakefileWorker, CMake, autoconf, and Visual Studio. The framework provides a starter project and resources for adding tests to legacy C code.
Key Features
C/C++ unit testing and mocking based on xUnit
Supports test-driven development (TDD)
Portable to many platforms including old ones
Simple design for easy use
MakefileWorker.mk for quick setup with gcc
Integration with Visual Studio via .sln files
Pre-packaged install via apt-get (Linux) and Homebrew (Mac)
Build from source with CMake or autoconf
Starter project available for gcc and Visual Studio
Resources for legacy C code test harness
Pros & Cons
Pros
- Open source and free to use
- Simple and easy to learn for developers familiar with xUnit
- Portable across many operating systems and compilers
- Strong support for embedded development
- Multiple installation options (package managers and source)
- Includes a MakefileWorker for quick test setup
- Good documentation and starter projects available
- Actively maintained on GitHub
Cons
- MakefileWorker not available in pre-packaged installations
- Requires some initial setup for non-standard environments
- Not as feature-rich as some modern C++ testing frameworks (e.g., Google Test)
Best For
Unit testing C/C++ applicationsTest-driven development in embedded systemsAdding tests to legacy C/C++ codebasesTesting cross-platform C/C++ projectsContinuous integration test suites
FAQ
How do I install CppUTest?
CppUTest can be installed via package managers (e.g., apt-get install cpputest on Debian/Ubuntu, brew install cpputest on Mac) or from source by cloning the GitHub repository and building with autoconf, CMake, or using MakefileWorker.mk.
Can I use CppUTest with Visual Studio?
Yes, CppUTest provides .sln files for Visual Studio (CppUTest_VS201x.sln for VS 2010 and later, CppUTest.sln for earlier versions). Build the project and set the CPPUTEST_HOME environment variable to use the static library.
What are the core design principles of CppUTest?
Simple in design and simple in use, portable to old and new platforms, and built with test-driven development for test-driven developers.
Does CppUTest support legacy C code?
Yes, CppUTest includes resources and recipes for adding tests to untested C and C++ code, with links to articles addressing real legacy C challenges. See the 'Get your Legacy C into a Test Harness' page.