libutest - C++ unit tests
-
std::vector - STL vector class
With this library it is possible to setup (recursive) unit tests for C++ programs. It is very simple to use. One only has to instantiate an object of class utest, specifying the number of (expected) (sub)tests and the name for this (sub)test suite.
Sub test suites can be put into scoped blocks or C(++) functions. Nesting is automagically accounted for. The example in section SYNOPSYS shows a way to make different test sections and put them all together in an overall test suite.
libutest is part of the elemental programming effort.
#include <utest.h>
int test_fails(void)
{
utest t(2,"SUBTEST for fail functionality");
B_UTEST(t,"test if fails==1");
{ int oks,fails,skips,aborts;
t.stats(oks,fails,skips,aborts);
t.test(fails==1,"this test should fail");
}
E_UTEST(t);
B_UTEST(t,"test if fails==1 (again)");
{ int oks,fails,skips,aborts;
t.stats(oks,fails,skips,aborts);
t.test(fails==1,"this test should be ok");
}
E_UTEST(t);
{ int oks,fails,skips,aborts;
t.stats(oks,fails,skips,aborts);
return (oks==1) && (fails==1) && (skips==0) && (aborts==0);
}
}
(...)
int main()
{
utest t(4,"Unit Tests for utest");
B_UTEST(t,"fail functionality");
t.test(test_fails());
E_UTEST(t);
B_UTEST(t,"skip functionality");
t.test(test_skips());
E_UTEST(t);
B_UTEST(t,"abort functionality");
t.test(test_aborts());
E_UTEST(t);
B_UTEST(t,"test/ok/nok/fail functionality");
t.test(test_test());
E_UTEST(t);
UTEST_EXIT(t);
}
This constructor instantiates a utest object with the given number of expected test cases and the description describing the test suite.
Description should be no longer than about 30 characters (for markup reasons).
This MACRO starts a new test case with given description.
This MACRO marks the end of a test case.
Signal that a test case has worked out OK. The comment should be no longer than about 30 characters (for markup reasons).
Signal that a test case failed.
Signal ok(), if testresult is not equal to 0 (zero); signal fail(), otherwise.
Signal skip this testcase and the next (nskip-1) following.
Abort this test suite, i.e. abort all following test cases.
If D==true, set debugging to stderr on. Turn it off otherwise.
Debug info will be logged to stderr and immediately fseeked.
If debugging mode is turned on, each B_TEST(...) (...) E_TEST(...) part will be logged.
Write msg to debug log.
Write msg to debug log.
This function gives back the current statistics about the current (sub) test suite.
This MACRO can be called at the end of a (sub) test suite and at the and of the ''main'' program. Executes a C(++) ''return'', returning 0 (zero), if there were no ''aborts'' nor ''fails'' in the test suite. returns 1 (one), otherwise.
Hans Oesterholt-Dijkema <hdnews -at- gawab.com>.
(c) Hans Oesterholt-Dijkema, Distributed under Artistic License.
$Id: utest.h,v 1.7 2004/07/20 09:45:06 cvs Exp $
Latest releases of all packages can be found here.



