Unit Test Frameworks
You have a lot of options when it comes to unit testing your C application. Many people even roll their own framework. While this isn't meant to be an exhaustive comparison of your options, we've selected some of the more common options that represent most types of options available. We hope you find this useful, even if you don't end up choosing ours. For a larger list, see the list on wikipedia.
We admit it, we're somewhat biased. But we'll try to stick to the facts. Unity has a number of features that make it stand out.
- It's pure C. If you're a C developer, you shouldn't have to break out your C++ compiler just to test something.
- It is very configurable, making it rock for embedded developers and other developers alike.
- While it's feature packed, the core features are still small. Unity is two header files and a single C file.
- If you'd like to automate away the repetitive tasks of testing, there are optional scripts for that.
- We have automatic mock generation (CMock) and a test build management system (Ceedling). Both are optional.
Google Test is a reliable and quickly growing option. It's a framework that is aimed at C++ developers, and many of the features are hard to reach for plain C, particularly the mocking features. If your code is a mix of C and C++, this is the first option I'd check out. It seems to have great support, is well thought out, and is feature rich.
CppUTest is an xUnit compatible C++ suite which has been designed with embedded developers in mind. It focuses on a reduced set of C++, so that C or C++ code can be tested directly. It has some nice features like fixtures, rudimentary memory leak detection, and mocking. It's also featured in the book Test Driven Development for Embedded C by James Grenning.
CHECK is a framework which focuses on ease-of-use. It's intended for unix C developers, though it supports Windows people too if they're willing to install MinGW or Cygwin. Like many of the C test frameworks, CHECK only supports a handful of assertions. They keep it intentionally small to keep it easier to learn, but this doesn't lend itself well to Embedded Developers.
CMocka has similar goals to Unity / CMock. They make some tradeoffs similar to CMockery, where they push more requirements on the user when developing tests in exchange for less emphasis on scripting. It's a pure C framework which relies on the C standard library functions. It support embedded and desktop users and aims at a compatibility for old C standards. That, and they have a really nice looking website.