Skip to content

Files

Failed to load latest commit information.

Latest commit

 Cannot retrieve latest commit at this time.

History

History

C_CppUTest

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.rst

C with CppUTest

Programming language: C (C99)
Unit test framework: CppUTest
Build automation: Make
Source code formatter: Artistic Style

Structure

Source files

  • src/main.c: the main application's entry point
  • src/module.*: the main application's functions that shall be tested
  • test/UnitTests.cc: unit tests; runs as a separate test application

Makefile targets

  • all: compile everything, i.e application and tests (default target)
  • clean: remove all files generated by make
  • main: compile and run main application
  • test: compile and run test application
  • format: ensure consistent source code formatting; see .astylerc for details
  • help: display available build targets

Usage: $ make <target>, e.g. $ make all or just $ make since all is the default target

Toolchain

This will install all necessary tools:

$ sudo apt-get install gcc g++ cpputest make astyle

Getting started

Setup

  1. Clone this repo: $ git clone https://github.com/makomi/tdd_templates.git
  2. Enter the template's folder: $ cd tdd_templates/C_CppUTest
  3. Checkout a new branch: $ git checkout -b dojo_yyyy-mm-dd

TDD cycle

A typical TDD cycle consisting of writing a test, writing the function code, and refactoring:

  1. Write a test in ./test/UnitTests.cc
  2. Compile and run the test: $ make test
  3. Write function code in ./src/module.h and ./src/module.c
  4. Compile and run the test: $ make test
  5. Refactor if the test passes
  6. Commit your results, e.g. $ git commit -am "Add test and function code for 'loneliness'"
  7. Repeat

In order to run the application, you will have to also follow these steps:

  1. Write application code in ./src/main.c
  2. Compile and run the application: $ make main

At the end you might want to delete all files generated by Make: $ make clean

Example Code

Have a look at the TDD examples repository to see this template in action with actual application and test code.

CppUTest

Manual

Have a look at the CppUTest manual for information on commonly used assertions, command line switches, additional memory leak detection, mocks, and more.

Scripts

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