I’ve been working with C unit testing frameworks for about six years now. Recently, I started using the CuTest framework for C unit testing, and it’s been a game-changer for me, especially in embedded systems. You can check it out here: CuTest homepage.
It’s ideal for embedded systems due to its lightweight and simple nature. I had no issues running it on both the target platform and the desktop. Here’s what you need to do:
- Include a header file wherever you call CuTest routines.
- Compile/link a single additional C file into the image.
- Add some simple code to
mainto set up and call the unit tests. This can be in a specialmain()function compiled ifUNITTESTis defined during the build.
The system needs to support a heap and some stdio functionality, but the code is simple enough to work around these requirements if necessary. With extern "C" {} blocks, it also supports testing C++ code.