Ktest provides a simple unit-test framework for C/C++ based projects.
- Simple Test suite interfaces
- No dependencies and completely written in C
- Pretty good test report with colored output
- Support Hooking to override the return values of function calls or an expressions in the production code
TEST_REPORT()
-- Print final Test reportRUN(test_function)
-- Run Testsuite, the collection of test casestest_function()
-- Function that contains the test cases
ASSERT(expr, hook_tag, hook_value)
TEST_INT_EQUAL(int a, int b, hook_tag, hook_value)
TEST_BOOL_EQUAL(int a, int b, hook_tag, hook_value)
TEST_STRING_EQUAL(int a, int b, hook_tag, hook_value)
KTEST_SETUP_HOOK(hook_tag, dest_datatype, dest_variable)
- Build Ktest from here and do
make
andmake install
- Library files will be save at
/usr/local/lib
- Header files will be save at
/usr/local/include
- Library files will be save at
- Compile the code with
gcc file.c -Wl,-rpath=/usr/local/lib/ -lktest
- Your code is ready to test
TEST_INT_EQUAL(4, 4, NULL, NULL);
TEST_INT_EQUAL(4, -1, NULL, NULL); /* FAIL */
TEST_BOOL_EQUAL(true, true, NULL, NULL);
TEST_STRING_EQUAL("Hello", "Hello", NULL, NULL);
ASSERT(2 == 2, NULL, NULL);
ASSERT(0 != strcmp("World", strdup("Work")), NULL, NULL);