This is the series on Unit testing in C for embedded development. The aim of this series is to provide easy and practical examples that anyone can understand. This is the Unit testing in C Part 3 – Ceedling installation. In our previous tutorial, we have discussed Code Coverage. Now we will discuss Unit Testing in C – Ceedling Installation.
Unit Testing in C – Ceedling Installation
I would recommend you to explore the relevant topics by using the below link.
What is Ceedling?
Ceedling is a Ruby gem that takes care of all the setup, building, and running of C unit tests. Ceedling is primarily targeted at Test-Driven Development in C. Ceedling includes a test framework (Unity), a mocking framework (CMock), and CException. These are the three other awesome open-source projects you can’t live without if you’re creating awesomeness in the C language.
Unity is an xUnit-style test framework for unit testing C. It is written completely in C and is portable, quick, simple, expressive, and extensible. It is designed to especially be also useful for unit testing for embedded systems.
CMock is an automated stub and mock generation framework made by a community of C developers, including Atom Greg Williams. It works within the Unity testing framework, and it is automatically included in any projects that use the Ceedling build management tool.
CMock autogenerates all functions defined in your code’s header files. It not only generates them, but it gives you additional functionality around those calls.
- Expectations allow you to specify functions that you expect to be called with specific values by the function under test.
- Returns allow you to specify what data the mocked function should return to the tested code.
- Ignores allow you to tell the code to ignore values from expectations if they’re not relevant to the test.
- Callbacks allow you to specify more complex mocked functionality.
CException is a project released by Throw The Switch. CException is designed to provide simple exception handling in C using the familiar
throw syntax. The library can be configured for either single-tasking or multi-tasking which makes this project a good fit for embedded systems using an RTOS.
CException is implemented in ANSI C and is highly portable. As long as your system supports the standard library calls
longjmp, you can use CException in your project. If you’re looking for an exception library to use on embedded systems, CException is for you.
- Supported Technology – C/C++
- User Interface – Command line
Now we will see how to install Ceedling.
Install the required tools
Ceedling requires both Ruby and GCC to run — so we’ll need to install those first.
Note: Ceedling will be run from the command line, and so you’ll also need to make sure that your path is set up correctly to point to both Ruby and GCC.
Ruby can be installed for Windows from rubyinstaller.org. You may want to check out the information on the downloads page about which version of Ruby to install.
Download the correct installer for your platform — either the 32-bit or the 64-bit (x64) version — and run the installer.
During installation, I recommend using the default installation folder and selecting to have Ruby added to the path. This will make it easier to install and use Ceedling from the command line.
Note:Be sure to select the option for Add Ruby executables to your PATH.
When the installer has finished, you can confirm that the installation was successful by opening up a command prompt and running
You can also install ruby in the Linux machine by using the below method.
Installing the tools for Linux should be relatively easy. The simplest way to install everything in Linux is with a package manager like
Install Ruby with
GCC is the native C compiler used for Ceedling. There are two primary ways to install GCC on Windows: via MinGW or Cygwin. I recommend MinGW for use with Ceedling. You can get MinGW from www.mingw.org via the MinGW installer. Download and run the installer. The default options should work fine.
You can install Ceedling though the Ruby package manager gem. The gem command should be available once Ruby is installed and available in your path. Just run:
Wail until its installed. That’s it. You can verify that ceedling is installed.
You can check the ceedling version using
That’s all. You have installed ceedling. In our next tutorial, we will see how to use ceedling.