Skip to content

TDD C++ Project Template - CppUTest and Unity

License

Notifications You must be signed in to change notification settings

embtool/tdd_cpp

Repository files navigation

TDD C/C++ Project Template - CppUTest and Unity

by Djones A. Boni

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.

Table of Contents

Quick-start

Create a build directory:

$ mkdir build
$ cd build

Build:

$ cmake ..
$ cmake --build .

Run the tests:

$ ctest

Run the application:

$ ./main

Developing an Application

  1. Add header files in include/.
  2. Add source files in src/.
  3. Add test files in tests/.
  4. Add header and source files to the embedded application library on CMakeLists.txt.
  5. Add one test for each test file on tests/CMakeLists.txt.

One-liner to build and test:

$ cmake .. && cmake --build . && ctest --output-on-error

AVR toolchain

CppUTest does not build with avr-g++, so we disable it.

$ cmake .. --toolchain ../cmake/toolchains/avr.cmake -DCPPUTEST_COMPILE_TESTS=OFF
$ cmake --build .

ARM toolchain (Cortex-M3)

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"

ARM toolchain (ARM926EJ-S)

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 .

About

TDD C++ Project Template - CppUTest and Unity

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published