gcc 4.7.2
c89
Hello,
I am wondering does any one know of any tutorials or text books that cover using makefile to create some simple unit testing for my c programs.
I would like to run some automated testing that will create a test suite and add this to my Makefile.
Just want some ideas on how to get started.
Many thanks for any suggestions
Generating Test Function Snippets
Generating function snippets is easy with the help of
gccxmlandnm. The following bash scriptgenerate_snippets.shcan be called with one command line argument to generate a test function snippet for each function defined in a source file:TODOS
The script is not yet perfect. You should probably include a test to only generate test functions for those functions which aren’t tested yet. As this is done analogous to finding the common names between
$Xand$Y, I leave this as an exercise. When this is implemented, it makes sense to run this script from a Makefile. See the other answer for pointers on that.Example Usage
Consider the C file
hello.c:Running the script above with this file as input yields the following output:
Just put those snippets into the appropriate file and fill them with logic as needed. After that, compile the test suite and run it.