You are here
Home > embedded > Testing >

Software Unit Testing With Ceedling

Ceedling is one of the best test automation framework for doing unit testing of your embedded C software system code. Unit testing is code that calls some other code to check if it performing as expected. Ceedling is specifically designed for running unit tests for C language code. Ceedling has feature of automatic generation of mock.

  • Unity is a unit test framework.
  • CMock creates the fake versions of other modules. Using these fake versions we can verify whether our module is working correctly or not.
  • Ceedling include unit test framework(Unity) and Mocking framework(CMock).
  • It requires Ruby to run as Ceedling build system uses rake files.
  • Ceedling comes with a command line tool that can be used to generate the project.

Check out details on how to mock local variable in ceedling, and An example project demonstrating how to configure Ceedling for use with Microchip’s ATSAME54 Micro-controller.

Ceedling uses CMock and Unity. Unity and CMock are open source tools for testing C code.


CMock –

It generates mock functions or stub functions by parsing the C header file. It creates mocks for each function in C language. Cmock generates five different types of mock functions Expect, Array, Callback, Cexception and Ignore. These functions are generated at run time.

Unity –

Unity is open source test framework which generates test runners, auto generated test files for each test. With this test framework alone I can test code for microcontrollers. For using unity it requires to add test code in each functions. Unity had provided assertion lists using which I can create test stubs. This requires going through all assertion lists and using appropriate one for the code. In order to avoid this hustle Ceedling is preferred test build management system, which takes care of build, test and reports.

Getting Started – Embedded Software Unit Testing With Ceedling

First install latest ruby. Ceedling uses rake build system so if you have latest ruby then installation of ceedling is just one line command.

gem install ceedling

Now create project with ceedling to configure your test build system.

ceedling new TestProjectName

In ‘TestProjectName’ add the src files ie code under test and these will become part of the test build system. I am required to keep the test folder and src folder separate to this can be done in ‘project.yml’ file.

This created unit test, Now run the ceedling using following command. This will test all build and execute the unit tests.

ceedling test:all
Test 'TestUartDriver.c'
Generating dependencies for UartDriver.c...
Compiling UartDriver.c...
Linking TestUartDriver.out...
Running TestUartDriver.out...

Hope you have enjoyed reading embedded software unit testing with Ceedling.

Leave a Reply