Reputation: 7
I want to test my C code and decide to using check as testing Framework. But I don't understand how to compile the code? In the tutorial they have already very huge makefiles, but they do not explain how to build them or what gcc flags I need.
How can I execute my simple tests?
Upvotes: 3
Views: 1648
Reputation: 1573
Personally I am not familiar with Check.
I will recommend using CppUTest and reading TDD For Embedded C. It has a good explanation and works on both C and C++.
Another option is Unity, also documented in the referenced book.
Upvotes: 0
Reputation: 382
It's very simple to acomplish with autotools. In configure.ac you check for existance of Check unit testing framework on the target system:
PKG_CHECK_MODULES([CHECK],[check >= 0.8.2],[have_check="yes"],
AC_MSG_WARN(['Check' unit testing framework not found. It would be impossible to run unit tests!"])
[have_check="no"])
In Makefile.am you specify what files and how to compile to build unit tests:
if HAVE_CHECK
check_PROGRAMS = bin/some_unit_tests
bin_some_unit_tests_SOURCES = source1.c source2.c ...
bin_some_unit_tests_CFLAGS = -g -pg -O2 -fprofile-arcs -ftest-coverage ...
bin_some_unit_tests_LDFLAGS = -g -pg -no-install
bin_some_unit_tests_LDADD = @CHECK_LIBS@
TESTS = bin/some_unit_tests
TESTS_ENVIRONMENT = CK_FORK=yes
CK_VERBOSITY = verbose
CLEANFILES = some_unit_tests.log
endif
Then you run unit test by issuing the command:
make check
By using -pg flag you would be able to obtain profiling information from executing unit tests.
Upvotes: 1
Reputation: 7213
There are open source projects that use check for unit testing. One example is TORQUE. You can check out the source using svn. Currently you'd want the trunk to see unit tests - svn co svn://svn.clusterresources.com/torque/trunk
Look at the directory src/lib/Libutils/test/resizable_array for one example of how to set things up. Like bsa2000's answer says, there's a lot of setup in terms of altering makefiles.
Upvotes: 0
Reputation: 151
You could get an archive file called "libcheck.a" after "configure->make->make install". Usually the libcheck.a will be installed into "/usr/lib" or "/usr/local/lib" and Gcc could find the location of libcheck.a automatically. What you need to do is to add -lcheck option to your compiling commandline,such as "gcc -o test_add test_add.c -lcheck".
Beside check, There are also many other framework for c unit testing, e.g. lcut, cmockery
Upvotes: 0