This document explains how to write tests for this project using the CUnit framework for unit testing. Please note, this document does not cover the interface for the CUnit and you are highly encouraged to go through the CUnit documentations before writing any tests.
You will need to install the CUnit library before compiling your tests.
The structure is fairly simple. There are two main components for testing:
- The main file that is responsible for running all the tests you have written (can be found at test/test.c)
- The test suites files that contains the actual tests.
Currently we have three main test suites:
- Unit tests for the interface. test/testsuite.c
- Unit tests for helpers. test/helpers_testsuite.c
- Comprehensive tests.
Accoridng to what type of test you are creating, choose where to place your test.
A test is simply a function created to test some feature in the project. All the tests must have the following format:
static void name_of_function_to_be_tested_test_n(void)
{
}
Look at the conventions for naming a test.
After creating the function, you will have to include it with the other tests. Fortunately, this is also easy:
- Open test/test.c
- You will find two arrays at the top of the page: utests and ctests (comprehensive tests).
- Choose one according to what type of test are you adding.
- Add the following to the array {"test_name", test_name},
For example, adding name_of_function_to_be_tested_test_n to the tests:
static struct test utests[] = {
{"test1", test1}
{"test2", test2},
{"test3", test3},
....
....
{NULL, NULL}
}
will be
static struct test utests[] = {
{"test1", test1}
{"test2", test2},
{"test3", test3},
....
{"name_of_function_to_be_tested_test_n", name_of_function_to_be_tested_test_n},
{NULL, NULL}
}