Setting up test drivers is not enough. To have a real test driver that runs on your computer, a test manager must be created and some test observers must be assigned so that we can what is happening.



int main (int argc, char** argv) {
	using namespace Scrunitizer;

	TestManager manager;

	BriefSessionLog briefLogger (cerr);
	VerboseSessionLog verboseLogger (cerr, false);
	SessionReport screenReport (cerr, "Class 'Rect' Test Report", false);
	SessionReport fileReport (cout, "Class 'Rect' Test Report", false, false);
	ExecutionTracer tracer (manager, cout);

	manager.addObserver (&briefLogger);
	manager.addObserver (&verboseLogger);
	manager.addObserver (&tracer);
	manager.addObserver (&screenReport);
	manager.addObserver (&fileReport);

	ArgVector args (argv + 1, argv + argc);
	try {
		manager.configureFrom (args);
	} 
	catch (LogFileNameMissing& ex) {
		cerr << "ERROR: File name missing after option " << ex.getOptionId () << endl;
		exit (1);
	}
	catch (CannotOpenLog& ex) {
		cerr << "ERROR: Cannot open log file \"" << ex.getFileName () << "\"" << endl;
		exit (1);
	}
	if (args.size () > 0) {
		cerr << "ERROR: Unknown options:";
		ArgVector::iterator pivot = args.begin ();
		while (pivot != args.end ()) {
			cerr << " " << *pivot++;
		}
		cerr << endl;
		exit (1);
	}

	Scrunitizer::TestSuite* suite;
	try {
		suite = buildTestSuite (manager);
	}
	catch (IllegalTestSetUp) {
		cerr << "ERROR: Illegal test set-up!" << endl;
		exit (1);
	}

	cerr	<< endl
		<< "************************ Rectangle Test Demo **********************" << endl;

	manager.conduct (*suite);

	cerr	<< "**************************** End of Demo **************************" << endl
		<< endl;

	return 0;
}

  1. First the namespace Scrunitizer is used in the main function. That saves a lot of typing.
  2. A test manager is created. This manager will actually conduct the execution of all tests.
  3. Several test observers are created.
    • A BriefSessionLog for the brief default output.
    • A VerboseSessionLog that could be enabled (-v) to produce a bit more information while the tests run.
    • An enabled SessionReport that produces a report at standard out.
    • Another one, which is disabled by default, that could be used to write a report in a file if wanted (-rf).
    • Last but not least, an ExecutionTracer that could be enabled when some test crashes the whole executable.
  4. All the observers are registered in the test manager.
  5. A argument vector is created from the main function parameters (command line arguments). Donīt forget that the first element in argv is the executable name.
  6. The test manager is configured. This could lead to some exceptions. They are caught and handled accordingly.
  7. It is checked if some arguments are left, that means they are not handled by the manager or any observer. If that is the case, a message is printed and exit is called because the user has made some mistake.
  8. Now all tests are created. Also here, something could go wrong, so some error handling must be done.
  9. Finally, the manager is told to execute all unit tests.
The Scrunitizer C++ Unit Test Framework
by Bernd Linowski

[Scrunitizer]  [Overview]  [Cookbook]  [Download]  [Index]  [Linosphere]

Page generated: 1 Nov 2000
(C) by Bernd Linowski
scrunitizer@linosphere.de