Programming language: | C (C99) |
Unit test framework: | CppUTest |
Build automation: | Make |
Source code formatter: | Artistic Style |
src/main.c
: the main application's entry pointsrc/module.*
: the main application's functions that shall be testedtest/UnitTests.cc
: unit tests; runs as a separate test application
all
: compile everything, i.e application and tests (default target)clean
: remove all files generated by makemain
: compile and run main applicationtest
: compile and run test applicationformat
: ensure consistent source code formatting; see .astylerc for detailshelp
: display available build targets
Usage: $ make <target>
, e.g. $ make all
or just $ make
since all
is the default target
This will install all necessary tools:
$ sudo apt-get install gcc g++ cpputest make astyle
- Clone this repo:
$ git clone https://github.com/makomi/tdd_templates.git
- Enter the template's folder:
$ cd tdd_templates/C_CppUTest
- Checkout a new branch:
$ git checkout -b dojo_yyyy-mm-dd
A typical TDD cycle consisting of writing a test, writing the function code, and refactoring:
- Write a test in
./test/UnitTests.cc
- Compile and run the test:
$ make test
- Write function code in
./src/module.h
and./src/module.c
- Compile and run the test:
$ make test
- Refactor if the test passes
- Commit your results, e.g.
$ git commit -am "Add test and function code for 'loneliness'"
- Repeat
In order to run the application, you will have to also follow these steps:
- Write application code in
./src/main.c
- Compile and run the application:
$ make main
At the end you might want to delete all files generated by Make: $ make clean
Have a look at the TDD examples repository to see this template in action with actual application and test code.
Have a look at the CppUTest manual for information on commonly used assertions, command line switches, additional memory leak detection, mocks, and more.
In addition to cloning this repository, it is possible to call scripts located in /usr/share/cpputest/scripts/
to create initial header, source, and Test files. You can find out where on your system CppUTest is installed by using whereis
:
$ whereis cpputest cpputest: /usr/share/cpputest