Skip to content

Add Unit Tests

Add unit tests with ceedling to your project.

Ceedling brings together Unity, a unit testing framework written in 100% ANSI C, CMock for automating mock and stubs generation in C, plus Ceedling's build system for coordinating, executing, and summarizing test and release builds. It's unit testing designed for embedded and has extensive documentation. EmbedOps easily adds all the configurations needed to run ceedling unit tests and incorporates them into an existing embedOps pipeline.

Prerequisites

  • Created an EmbedOps project that is registered on the EmbedOps platform

Testing Out Unit Tests

To simply test out this functionality, you can follow the HIL Quick Start and add unit tests to that project using the examples in the steps below.

Steps

  1. Add unit test Template

    eo add unittest 
    
    It will then guide you through configuring the CI provider and which directories are for the source code under test and where the test code will live.

    If adding to the project created by the HIL Quick Start, select ceedling as the type, src as the source, and test as the test directory.

  2. Generate Ceedling JUnit XML

    Open dev container and run

    container> ci/ceedling.sh
    

    Via devcontainer CLI

    Install the devcontainer CLI and run it this way outside of the container. Example to install and run on Mac:

    MacOs
    host> brew install node
    host> sudo npm install -g @devcontainers/cli
    host> devcontainer up --workspace-folder .
    host> devcontainer exec --workspace-folder . ci/ceedling.sh
    
    Install on other OS following the official installation

    This will find the test_template.c file and run the test_template test. Since it sets expected and actual to different values, you'll get an error. It will also generate a JUnit XML file with your results, with the default location of build_test/artifacts/test/junit_tests_report.xml (the location is also printed in the console at the end of the test).

    The default test will fail and output the results on the console:

    Screenshot of the console showing ceedling output saying a test failed

Next Steps

Your project is now setup to run unit tests, you can start adding your own. Checkout the Ceedling documentation, or add extra reporting on the EmbedOps Platfowm with the Generate Reports How-to