Add Unit Tests
Add unit tests with ceedling or GoogleTest 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.
Meanwhile, GoogleTest is a testing framework developed by the Testing Technology team with Google’s specific requirements and constraints in mind. It supports C++ code, and works on any OS. And it supports any kind of tests, not just unit tests. Since GoogleTest is based on the popular xUnit architecture, it's easy to pick up if you’ve used JUnit or PyUnit before.
EmbedOps easily adds all the configurations needed to run ceedling OR GoogleTest unit tests and incorporates them into an existing embedOps pipeline. It also can setup optional code coverageusing gcov.
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
It will then guide you through configuring which testing framework to use, which directories are for the source code under test and where the test code will live, and if you want to have test coverage included.
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, and Yes
to code coverage.
Example video of the terminal:
2. Generate Ceedling JUnit XML
Open dev container and run
Via devcontainer CLI
Install the devcontainer CLI and run it this way outside of the container. Example to install and run on Mac:
host> brew install node
host> sudo npm install -g @devcontainers/cli
host> devcontainer up --workspace-folder .
host> devcontainer exec --workspace-folder . ci/ceedling.sh
This will find the test_ceedling.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:
Next Steps
Your project is now setup to run unit tests, you can start adding your own. Checkout the Ceedling documentation or GoogleTest Primer, or add extra reporting on the EmbedOps Platform with the Generate Reports How-to