From 41e210a888ae68e1d908e60d903a65672f068b14 Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Wed, 27 Mar 2002 16:56:47 +0000 Subject: Makefile. makefile.am: added src/CppUnitLibraries.dsw, new contribution, and src/qttestrunner. * TODO: updated (doc). * contrib/msvc/AddingUnitTestMethod.dsm: added, submitted by bloodchen@hotmail.com. * constrib/msvc/readme.txt: updated. * include/cppunit/TestAsserter.h: * include/cppunit/SourceLine.h: updated doc. * include/cppunit/TestCaller.h: reindented. updated doc. * include/cppunit/extensions/HelperMacros.h: relaxed constraint on fixture. Fixture base class may be TestFixture instead of TestCase. * include/cppunit/TestCase.h: * src/cppunit/TestCase.h: TestCase inherits TestFixture for setUp() and tearDown() definition. Moved documentation to TestFixture. * include/cppunit/TestFixture.h: updated documentation. * include/cppunit/TestRegistry.h: * src/cppunit/TestRegistry.cpp: Removed. Replaced by TestFactoryRegistry. * include/cppunit/TextTestRunner.h: * src/cppunit/TextTestRunner.cpp: made printing progress using a TextTestProgressListener optional. * examples\cppunittest\ExceptionTest.h: * examples\cppunittest\HelperMacrosTest.h: * examples\cppunittest\HelperMacrosTest.cpp: * examples\cppunittest\NotEqualException.h: * examples\cppunittest\OrthodoxTest.h: * examples\cppunittest\RepeatedTest.h: * examples\cppunittest\TestAssertTest.h: * examples\cppunittest\TestCallerTest.h: * examples\cppunittest\TestDecoratorTest.h: * examples\cppunittest\TestFailureTest.h: * examples\cppunittest\TestResultCollectorTest.h: * examples\cppunittest\TestResultTest.h: * examples\cppunittest\TestSetUpTest.h: * examples\cppunittest\TestSuiteTest.h: * examples\cppunittest\XmlOutputterTest.h: * examples\cppunittest\XmlOutputterTest.cpp: * examples\cppunittest\XmlUniformizerTest.h: * examples\cppunittest\XmlUniformizerTest.cpp: changed base class for fixture from TestCase to TestFixture. * examples\hierarchy\BoardGameTest.h: * examples\hierarchy\ChessTest.h: * examples\hierarchy\main.cpp: updated to use HelperMacros for correct fixture instantiation (the ChessBoard::testReset test case was using BoardGame fixture instance instead of ChessBoard). --- src/cppunit/TextTestRunner.cpp | 51 ++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 19 deletions(-) (limited to 'src/cppunit/TextTestRunner.cpp') diff --git a/src/cppunit/TextTestRunner.cpp b/src/cppunit/TextTestRunner.cpp index edf7c85..e17abe9 100644 --- a/src/cppunit/TextTestRunner.cpp +++ b/src/cppunit/TextTestRunner.cpp @@ -8,15 +8,8 @@ namespace CppUnit { -/** Constructs a test runner with the specified TestResult. - * - * A TextTestRunner owns a TextTestResult. It can be accessed - * anytime using result(). If you run the test more than once, - * remember to call result()->reset() before each run. - * - * \param result TextTestResult used by the test runner. If none - * is specified then a default TextTestResult is - * instanciated. +/*! Constructs a new text runner. + * \param outputter used to print text result. Owned by the runner. */ TextTestRunner::TextTestRunner( Outputter *outputter ) : m_outputter( outputter ) @@ -39,7 +32,7 @@ TextTestRunner::~TextTestRunner() } -/** Adds the specified test. +/*! Adds the specified test. * * \param test Test to add. */ @@ -51,7 +44,7 @@ TextTestRunner::addTest( Test *test ) } -/** Runs the named test case. +/*! Runs the named test case. * * \param testName Name of the test case to run. If an empty is given, then * all added test are run. The name must be the name of @@ -60,15 +53,18 @@ TextTestRunner::addTest( Test *test ) * before the run() method exit. * \param printResult if \c true (default) then the test result are printed * on the standard output. + * \param printProgress if \c true (default) then TextTestProgressListener is + * used to show the progress. * \return \c true is the test was successful, \c false if the test * failed or was not found. */ bool TextTestRunner::run( std::string testName, bool doWait, - bool doPrintResult ) + bool doPrintResult, + bool printProgress ) { - runTestByName( testName ); + runTestByName( testName, printProgress ); printResult( doPrintResult ); wait( doWait ); return m_result->wasSuccessful(); @@ -76,14 +72,15 @@ TextTestRunner::run( std::string testName, bool -TextTestRunner::runTestByName( std::string testName ) +TextTestRunner::runTestByName( std::string testName, + bool printProgress ) { if ( testName.empty() ) - return runTest( m_suite ); + return runTest( m_suite, printProgress ); Test *test = findTestByName( testName ); if ( test != NULL ) - return runTest( test ); + return runTest( test, printProgress ); std::cout << "Test " << testName << " not found." << std::endl; return false; @@ -126,16 +123,22 @@ TextTestRunner::findTestByName( std::string name ) const bool -TextTestRunner::runTest( Test *test ) +TextTestRunner::runTest( Test *test, + bool printTextProgress ) { TextTestProgressListener progress; - m_eventManager->addListener( &progress ); + if ( printTextProgress ) + m_eventManager->addListener( &progress ); test->run( m_eventManager ); - m_eventManager->removeListener( &progress ); + if ( printTextProgress ) + m_eventManager->removeListener( &progress ); return m_result->wasSuccessful(); } +/*! Returns the result of the test run. + * Use this after calling run() to access the result of the test run. + */ TestResultCollector & TextTestRunner::result() const { @@ -143,6 +146,10 @@ TextTestRunner::result() const } +/*! Returns the event manager. + * The instance of TestResult results returned is the one that is used to run the + * test. Use this to register additional TestListener before running the tests. + */ TestResult & TextTestRunner::eventManager() const { @@ -150,6 +157,12 @@ TextTestRunner::eventManager() const } +/*! Specifies an alternate outputter. + * + * Notes that the outputter will be use after the test run only if \a printResult was + * \c true. + * \see CompilerOutputter, XmlOutputter, TextOutputter. + */ void TextTestRunner::setOutputter( Outputter *outputter ) { -- cgit v1.2.1