C/C++ Project Template for Test Driven Development using CppUTest and Unity test frameworks.
Unity test runners are generated automatically.
Tests for CppUTest are automatically converted to Unity, so they can run on platforms that only have a C compiler.
It is possible to disable the compilation and execution of CppUTest
tests and Unity tests by setting CPPUTEST_COMPILE_TESTS
,
CPPUTEST_CONVERT_TESTS
, and UNITY_COMPILE_TESTS
variables on CMake
(see the table below).
CMake definitions | Description |
---|---|
-D DEV_BUILD=OFF |
Disable developer build. |
-D CPPUTEST_COMPILE_TESTS=OFF |
Disable CppUTest tests. |
-D CPPUTEST_CONVERT_TESTS=OFF |
Disable CppUTest conversion to Unity. |
-D UNITY_COMPILE_TESTS=OFF |
Disable Unity tests. |
Create a build directory:
$ mkdir build
$ cd build
Build:
$ cmake ..
$ cmake --build .
Run the tests:
$ ctest
Run the application:
$ ./main
- Add header files in include/.
- Add source files in src/.
- Add test files in tests/.
- Add header and source files to the embedded application library on CMakeLists.txt.
- Add one test for each test file on tests/CMakeLists.txt.
One-liner to build and test:
$ cmake .. && cmake --build . && ctest --output-on-error
CppUTest does not build with avr-g++, so we disable it.
$ cmake .. --toolchain ../cmake/toolchains/avr.cmake -DCPPUTEST_COMPILE_TESTS=OFF
$ cmake --build .
CppUTest uses too much dynamic memory (heap RAM), so we disable it.
$ cmake .. --toolchain ../cmake/toolchains/arm.cmake -DCPPUTEST_COMPILE_TESTS=OFF
$ cmake --build .
It is possible to pass MACHINE_CPU and LINKER_SCRIPT to cmake. These are the defaults:
$ cmake .. --toolchain ../cmake/toolchains/arm.cmake -DCPPUTEST_COMPILE_TESTS=OFF -DMACHINE_CPU="-mcpu=cortex-m3" -DLINKER_SCRIPT="../linker/cortex-m3.ld"
This processor allows much more RAM, so we can keep CppUTest enabled too.
$ cmake .. --toolchain ../cmake/toolchains/arm.cmake -DMACHINE_CPU="-mcpu=arm926ej-s" -DLINKER_SCRIPT="../linker/arm926ej-s.ld"
$ cmake --build .