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.
| autounit_suite_t | C-Unit Types |
|
This type holds summary information about a suite, pointers to setup
and teardown functions and a list of |
| autounit_test_fp_t | C-Unit Types |
|
A typedef pointer to a function that excutes a test. |
| autounit_test_t | C-Unit Types |
|
This type holds information about a test and a pointer to code to be excecuted.
It is normally "contained" by a |
| autounit_test_setup_fp_t | C-Unit Types |
|
A pointer to a setup function called before each test. This function usually creates datastructures for the test functions to play with. |
| autounit_test_teardown_fp_t | C-Unit Types |
|
A pointer to a teardown function called after each test. This function usually frees datastructures created by the setup function. |
| autounit_stress_report_t | C-Unit Types |
|
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 (test,err_msg,expression) | C-Unit Macros |
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);
|
| autounit_suite_t * au_new_suite (GString *name, autounit_test_setup_fp_t setup_fp, autounit_test_teardown_fp_t teardown_fp) | C-Unit Functions |
au_new_suite allocates a autounit_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);
|
| autounit_test_t * au_new_test (GString *name, autounit_test_fp_t test_fp) | C-Unit Functions |
|
After tests are created, the developer should use autounit_test_t *tmp_test = au_new_test("test name", test_another_feature);
|
| autounit_suite_t * au_add_test (autounit_suite_t *tc, autounit_test_t *test) | C-Unit Functions |
|
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);
|
| gint au_run_suite (autounit_suite_t *tc) | C-Unit Functions |
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);
|
| gint au_run_stress_suite (autounit_suite_t *tc, gint rounds, gint modulo) | C-Unit Functions |
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. ;)