Software using C for unit testing should include autounit/autounit.h. This file will define prototypes and datastructures that will be used by your test suite.
Add the linker option -lau-c-unit
for your test suite.
Autounit comes with autoconf macros installed into
$prefix/share/aclocal. If your project uses autoconf to help set up
builds you can put AM_PATH_AUTOUNIT
macro in your configure.in run
aclocal to grab the macros and rerun autoconf. The macro will define
AUTOUNIT_CFLAGS
and AUTOUNIT_LIBS
to be used in your
Makefile.am or Makefile.in.
This type holds summary information about a suite, pointers to setup and teardown functions and a list of
autounit_test_t
structures.
This type holds information about a test and a pointer to code to be excecuted. It is normally "contained" by a
autounit_suite_t
.
A pointer to a setup function called before each test. This function usually creates datastructures for the test functions to play with.
A pointer to a teardown function called after each test. This function usually frees datastructures created by the setup function.
This struct holds configuration information for how often to print "(test round)...." status during a stress test.
The code examples from this reference are excerpts from c-unit-suite.c. In some cases, they were modified to reduce the amount of "context" needed to understand the example. Developers seeking to understand better how to use C-Unit should read the source for c-unit-suite.c directly to see all the context.
au_assert
evaluates expression, when expression is false, err_msg is appended to the status for test. When expression is true, no changes are made to test. One should be wary of side-effects when writing expression.au_assert(t,"string not what we expected",strcmp(str,"hello")==0);
au_new_suite
allocates aautounit_suite_t
structure and initializes it with name and setup_fp and teardown_fp.autounit_suite_t *c_unit_test_suite = au_new_suite(g_string_new("Autounit C Unit Self Test"), cus_setup_suite,cus_teardown_suite);
au_new_test
allocates aautounit_test_t
structure and initializes it with name and test_fp.After tests are created, the developer should use
au_add_test
to install into a suite. Unless the developer usesau_test_ref
the test will be freed when removed from a suite or when the suite is deleted.autounit_test_t *tmp_test = au_new_test("test name", test_another_feature);
The pointer to the suite that was added to is returned and is the same as the suite given.
au_add_test(c_unit_test_suite,tmp_test);
au_run_suite
iterates through it's list of tests calling the setup fuction before the test code and then the teardown function.result = au_run_suite(c_unit_test_suite);
au_run_stress_suite
iterates through it's list of tests rounds times printing feedback every modulo rounds.result = au_run_stress_suite(c_unit_stresstest_suite,25,5);
There are no utilities as of yet.
I think running c-unit-suite is good enough, no need to duplicate all that stuff here. ;)