namespace unitpp

The unitpp name space holds all the stuff needed to use the unit++ testing framework.

class test
The heart of a test system: A test.
template<typename C> class test_mfun: public test
A test that is implemented by a member function
class testcase
A ref counted reference to a test.
template<typename E> class exception_test: public test
A wrapper class for the testcase class that succedes if the correct exception is generated
template<typename E> testcase exception_case(const testcase& tc)
Generate a testcase that expects a specific exception from the testcase it wraps.
extern std::vector<std::string> vectorize(const std::string& str, char c)
Splits the string by char c.
class suite: public test
A suite is a test that happens to be a collection of tests.
class visitor
The visitor class is a base class for classes that wants to participate in the visitor pattern with the test hierarchi.
class assertion_error: public std::exception
The basic for all failed assert statements
template<class T1, class T2> class assert_value_error: public assertion_error
This exception represents a failed comparison between two values of types T1 and T2.
inline void fail(const std::string& msg)
The test was not succesful
template<class A>inline void assert_true(const std::string& msg, A assertion)
Assert that the assertion is true, that is fail if (!assertion) 
template<class T1, class T2>inline void assert_eq(const std::string& msg, T1 exp, T2 got)
Assert that the two arguments are equal in the == sense
options_utils::optmap& options()
The singleton instance of the option handler of main.
class gui_hook
An instance of this class hooks the GUI code into the test executable.
class test_runner
A runner is the base class for the objects that actually processes the tests from main.
void set_tester(test_runner*)
Sets the test_runner to be used in testing.
class plain_runner: public test_runner
A plain test runner for the ordinary text version
class res_cnt
A mostly internal class for keeping score
class tester: public visitor
The standard text based tester.
class cnt_item: public QHBox
A colored count with a unit
class cnt_line: public QHBox
A line with total, ok, fail, and error counts
class res_stack: public QVBox
A cnt_line stacked with a progress bar
class gui: public QVBox
The whole GUI box with test tree, results, and buttons
class node: public QObject
A node in the test tree.
class suite_node: public node
A specialized node representing a test suite
class g_setup: public QObject, public visitor
The class for setting up the GUI.


Documentation

The unitpp name space holds all the stuff needed to use the unit++ testing framework.

The normal way to make a test is like this:

#include<unit++.h>
using namespace unitpp;
// use anonymous namespace so all test classes can be named Test
namespace {
class Test : public suite {
	void test1()
	{
		// do test stuff
		assert_true("message", exp1); // exp1 should be true
		assert_eq("another msg", 123456, exp2); // exp2 should be 123456
		// ...
	}
	void test2()
	{
		// do something that provokes exception out_of_range
	}
public:
	Test() : suite("appropriate name for test suite")
	{
		// any setup you need
		add("id1", testcase(this, "Test 1", &Test::test1));
		// make a testcase from the method
		testcase tc(this, "Test 2", &Test::test2);
		// add a testcase that expects the exception
		add("id2", exception_case<out_of_range>(tc));
		// add the suite to the global test suite
		suite::main().add("id", this);
	}
} * theTest = new Test();  // by new, since testcase claims ownership
}

In order to make an executable test, simply link the above code against libunit++, something like

g++ -o test++ mytest.cc -L <location of libunit++> -lunit++

This will generate a test called test++ and the standard behaviour for a test. Note that most shells have test defined as a shell builtin which makes it a moderately bad name for a program, since it is rather hard to get executed, hence test++.

See Also:
main

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.