Building and Running Unit Tests

Previous: Using the console

The project builds are set up using cmake. Find the required version under Set up your environment.

Unit tests are generally set up in each module in the test folder, however to build and run them the configuration and mocks provided under executables/unitTest are required.

Configure and generate a project buildsystem for the unit test build:

cmake --preset tests-posix-debug

Build all tests or a specified target:

# all tests for generic modules
cmake --build --preset tests-posix-debug
# specific target
cmake --build --preset tests-posix-debug --target <target>
# example
cmake --build --preset tests-posix-debug --target ioTest

Find all available targets for the unit test build:

cmake --build --preset tests-posix-debug --target help

Configure and build tests for platform specific modules other than POSIX:

# S32K1XX
cmake --preset tests-s32k1xx-debug
cmake --build --preset tests-s32k1xx-debug

Prepare a clean build using the clean target:

cmake --build --preset tests-posix-debug --target clean

Run the tests:

ctest --preset tests-posix-debug --parallel

If you modified some CMakeLists.txt files in the project don’t forget to run:

cmake-format -i $(find . -name CMakeLists.txt | sed '/3rdparty\/.*\/CMakeLists\.txt/d')

Next: Managing the lifecycle of components