I'm using cppunit to run a suite of about 700 unit tests. The
test runner is of type CppUnit::TextUi::TestRunner. The runner
prints a period for every test that successfully completes, an
"E" for errors, and an "F" for failed assertions.
However, it only outputs to the screen at the end of the entire
set of tests.
Is it possible to output after each test, so that the person
running the test gets some assurance that the test app is
still running and hasn't just hung? In other words, is there
an output handler that fflush'es after every test? If not,
where's the best place to look for guidance on how to write one?
First poster -- thanks for your help. I've searched the archives
for "fflush" and haven't found anything -- maybe I should be using
a more C++ish keyword, but I'm more familiar with C...
Cheers,
William
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm using cppunit to run a suite of about 700 unit tests. The
test runner is of type CppUnit::TextUi::TestRunner. The runner
prints a period for every test that successfully completes, an
"E" for errors, and an "F" for failed assertions.
However, it only outputs to the screen at the end of the entire
set of tests.
Is it possible to output after each test, so that the person
running the test gets some assurance that the test app is
still running and hasn't just hung? In other words, is there
an output handler that fflush'es after every test? If not,
where's the best place to look for guidance on how to write one?
First poster -- thanks for your help. I've searched the archives
for "fflush" and haven't found anything -- maybe I should be using
a more C++ish keyword, but I'm more familiar with C...
Cheers,
William
Here's how I was able to fix this, for the benefit of anyone else who's interested.
FlushingTextTestProgressListener.cpp:
====
#include "FlushingTextTestProgressListener.h"
#include <cppunit/TestFailure.h>
#include <cppunit/portability/Stream.h>
using namespace CppUnit;
FlushingTextTestProgressListener::FlushingTextTestProgressListener() {}
FlushingTextTestProgressListener::~FlushingTextTestProgressListener() {}
void FlushingTextTestProgressListener::startTest( Test *test ) {
stdCOut() << "."; stdCOut().flush();
}
void FlushingTextTestProgressListener::addFailure( const TestFailure &failure )
{
stdCOut() << (failure.isError() ? "E" : "F" ); stdCOut().flush();
}
void FlushingTextTestProgressListener::endTestRun( Test *test,
TestResult *eventManager ) {
stdCOut() << "\n"; stdCOut().flush();
}
====
FlushingTextTestProgressListener.h:
====
#ifndef CPPUNIT_FLUSHINGTEXTTESTPROGRESSLISTENER_H
#define CPPUNIT_FLUSHINGTEXTTESTPROGRESSLISTENER_H
#include <cppunit/TestListener.h>
class FlushingTextTestProgressListener :
public CppUnit::TestListener
{
public:
FlushingTextTestProgressListener();
~FlushingTextTestProgressListener();
void startTest( CppUnit::Test *test );
void addFailure( const CppUnit::TestFailure &failure );
void endTestRun( CppUnit::Test *test,
CppUnit::TestResult *eventManager );
};
#endif // ndef CPPUNIT_FLUSHINGTEXTTESTPROGRESSLISTENER_H
====
Then in my main test, include the following include lines:
======
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/TestResult.h>
#include "FlushingTextTestProgressListener.h"
======
and the following code lines:
=====
CppUnit::TextUi::TestRunner runner;
// add tests...
FlushingTextTestProgressListener progress;
runner.eventManager().addListener( &progress );
bool rval = runner.run();
=====
Hope this is of use to someone.
Cheers,
William