A traditional unit testing library for C.
cest's current features:
- Single test execution.
- Test suite creation and execution.
- Before suite startup and after finishing hooks.
- cest-git on AUR
- make
- libc
- gdb
- valgrind
cest works for now only on GNU/Linux based operating systems.
user@machine$ make
user@machine$ make check
user@machine$ make install INSTALL_DIR=/usr/
INSTALL_DIR is /usr/ by default.
All executed make tasks should complete successfully.
- Compile against libcest.so.
user@machine$ gcc test.c -lcest -o CestSampleTest
The test suite conctructor is in its early stages with extremely small and basic features. Using the API is the way to go if you're going to use test hooks.
#include <cest/create_test_suite.h>
START_TEST_SUITE("Test that test is test")
int pow(int x){
return x*x;
}
TEST("Test that pow(0) is zero",(Assert *assert){
Assert_assertTrue(assert,pow(0) == 0);
});
TEST("Test that pow(2) == 4",(Assert *assert){
Assert_assertTrue(assert,pow(2) == 4);
});
END_TEST_SUITE
- Include cest's test header.
#include <cest/cutest.h>
- Create test function globally.
void test_function(Assert *assert){
Assert_assertTrue(assert, 1+1 == 2);
}
- Create single test.
CUTest *test = CUTest_create("Test name is here", test_function);
- Execute test.
CUTest_execute(test);
CUTest_didTestPass(test); //returns 1 if test passed; 0 otherwise.
- Include cest's test suite header.
#include <cest/cutestsuite.h>
- Create test suite.
CUTestSuite *testSuite = CUTestSuite_create("Passing Test Suite");
CUTestSuite_addTest(testSuite, "passing test", passingTest);
- Execute test suite.
CUTestSuite_execute(testSuite);
CUTestSuite_didPass(testSuite); //returns 1 if test passed; 0 otherwise.
void beforeStartHook() {
// Setup suite
}
void afterFinishtHook() {
// Teardown suite
}
CUTestSuite_runHookBeforeStartingSuite(testSuite, beforeStartHook);
CUTestSuite_runHookAfterFinishingSuite(testSuite, afterFinishHook);
To Destroy test suite:
CUTestSuite_destroy(testSuite);
similarly for any destroying a lone test:
CUTest_destroy(test);
Test Suites (or single tests) are better destroyed if execution of the test suite (or test) has finished and it's not used again.
To debug any test from the test suite use the following command:
[user@machine ~]$ make test-debug TEST=test_name
This command launches gdb on the target test.