Installation
Eine gute Anleitung zur Installation befindet sich hier: http://w3.scs.ryerson.ca/~schi/cps707/install-linux.html.
Ich musste auf meinem Debian 6 nachträglich noch den Pfad für die Libs in den LD_LIBRARY_PATH aufnehmen bzw. den ldconfig Befehl ausführen.
export LD_LIBRARY_PATH=/usr/local/lib
Beispielkonfiguration
Ein Basic-Test lässt sich mit dem folgenden Template für einen cUnit Test realisieren:
#include
#include
#include "CUnit/Basic.h"
/*
* Set up test suite.
* Returns zero on success, non-zero otherwise.
*/
int setup_suite(void) {
return 0;
}
/*
* Tear down test suite.
* Returns zero on success, non-zero otherwise.
*/
int teardown_suite(void) {
return 0;
}
/*
* Foo test method
*/
void testFOO(void) {
CU_ASSERT(1);
}
/*
* bar test method
*/
void testBAR(void) {
CU_ASSERT(1);
}
/*
* The mandatory main() function.
*/
int main() {
CU_pSuite pSuite = NULL;
// init cunit registry
// return error if init fails
if (CUE_SUCCESS != CU_initialize_registry()) {
return CU_get_error();
}
// add test suite to the registry
pSuite = CU_add_suite("Testsuite", setup_suite, teardown_suite);
if (NULL == pSuite) {
// cleanup and return error
CU_cleanup_registry();
return CU_get_error();
}
// add the tests to the test suite
if (NULL == CU_add_test(pSuite, "test of xyz", testFOO) || CU_add_test(pSuite, "test of xyz", testBAR))
{
// cleanup and return error
CU_cleanup_registry();
return CU_get_error();
}
// set output level (CU_BRM_VERBOSE|CU_BRM_NORMAL|CU_BRM_SILENT)
CU_basic_set_mode(CU_BRM_NORMAL);
// run tests
CU_basic_run_tests();
// cleanup
CU_cleanup_registry();
return CU_get_error();
}