cmake-cmocka-tdd-template
|
This is a template for test driven development tdd for a C project. The project gets generated by cmake
and build by gcc
. The tests use the integrated ctest
funcionality of cmake and are written with the cmocka framework. Additionally doxygen
is used to automaticly generate source code documentation and cppcheck
to statically analyze the source code.
Version in brackets is what was used at the time of writing.
A Dockerfile is available for easy setup of the needed tools. Or even easier as prebuilt image on dockerhub nikolodion/cmake-tdd. If VSCode or another supported editor is used one could also use the additional devcontainer.json to setup the environment automatically.
Please note that the commands have to be executed from the build
subdirectory.
command | action | |
---|---|---|
cmake .. | generate buildsystem | |
make | compile source code | executable can be found under build/src/ |
make test_cmocka | run cmocka tests | |
make test_cppcheck | check source code with cppcheck | |
make tests | run all tests | cmocka & cppcheck |
make doc | generate documentation | to view open build/doc/html/index.html |
make clean | remove compiled files |
If VSCode is used these commands are also available as tasks in tasks.json.
src
a file that tests the implementation should be created here. The cmocka framework makes this very easy.[MIT](LICENSE) © NikLeberg.