TextTestProgressListener

   
TextTestProgressListener

Description

The class TextTestProgressListener (see Figure C-35) is a subclass of TestListener . It prints a textual "progress bar" indicating the progress of a series of tests as they are run. A sample of its output is shown here:

 ....F...E... 

This shows that 10 tests were run, and 1 failure and 1 error occurred.

TextTestProgressListener belongs to the namespace CppUnit . It is declared in TextTestProgressListener.h and implemented in TextTestProgressListener.cpp .

Figure C-35. The class TextTestProgressListener
figs/utf_ac35.gif

Declaration

 class TextTestProgressListener : public TestListener 

Constructors/Destructors


TextTestProgressListener( )

A constructor.


virtual ~TextTestProgressListener( )

A destructor.

Public Methods


void addFailure(const TestFailure &failure)

A method that informs TextTestProgressListener of a TestFailure . If the TestFailure is an assertion failure, an F is printed; otherwise , an E is printed.


void done( )

Prints a carriage return and flushes the output stream to complete the output.


void startTest(Test *test)

A method that informs TextTestProgressListener that a Test is about to be run. A period ( .) is printed to indicate progress.

Protected/Private Methods


TextTestProgressListener(const TextTestProgressListener& copy)

A copy constructor, scoped private to prevent its use.


void operator=(const TextTestProgressListener& copy)

A copy operator, scoped private to prevent its use.

Attributes

None.

   
TextTestResult

Description

This class is deprecated and should not be used. The classes TextTestProgressListener and TextOutputter replace it.

TextTestResult is declared in TextTestResult.h and implemented in TextTestResult.cpp .

   
XmlOutputter

Description

The class XmlOutputter (see Figure C-36) is a subclass of Outputter . It gets test results from a TestResultCollector and outputs them in XML format to an output stream. The write( ) method is called to produce the output, rather than calling the other output methods directly.

XmlOutputter defines a nested class named Node representing an XML node.

XmlOutputter belongs to the namespace CppUnit . It is declared in XmlOutputter.h and implemented in XmlOutputter.cpp .

Figure C-36. The class XmlOutputter
figs/utf_ac36.gif

Declaration

 class XmlOutputter : public Outputter 

Constructors/Destructors


XmlOutputter(TestResultCollector *result, ostream &stream, string encoding = "ISO-8859-1")

Constructs an XmlOutputter to get test results from result and output them to stream . The default encoding is ASCII, also known as Latin-1 or ISO 8859-1.


virtual ~XmlOutputter( )

A destructor.

Public Methods


virtual void addFailedTest(Test *test, TestFailure *failure, int testNumber, Node *testsNode)

Creates an XML node representing the test failure and adds it to testsNode . Also calls addFailureLocation() if the test failure has a valid SourceLine .


virtual void addFailedTests(FailedTests &failedTests, Node *rootNode)

Adds the test failures from failedTests to rootNode using addFailedTest( ) .


virtual void addFailureLocation(TestFailure *failure, Node *testNode)

Creates an XML node representing the test failure location and adds it to testNode .


virtual void addStatistics(Node *rootNode)

Creates an XML node containing the number of tests, number of failures, and number of errors, and adds it to rootNode .


virtual void addSucessfulTest(Test *test, int testNumber, Node *testsNode)

Creates an XML node representing a test success and adds it to testsNode .


virtual void addSucessfulTests(FailedTests &failedTests, Node *rootNode)

Adds the successful tests from the TestResultCollector to rootNode using addSucessfulTest( ) .


virtual Node *makeRootNode( )

Creates a Node and adds the test results to it using addFailedTests( ) , addSucessfulTests( ) , and addStatistics() .


virtual void writeProlog( )

A method that writes the XML prolog (header), which includes the XML version (1.0) and the encoding type.


virtual void writeTestsResult( )

A method that writes the body of the XML document. Calls makeRootNode( ) and writes the resulting Node to the output stream as a string .


void write( )

Method called to write the test results to the output stream as an XML document. Calls writeProlog( ) and writeTestsResult( ) .

Protected/Private Methods


virtual void fillFailedTestsMap(FailedTests &failedTests)

A protected method to get the test failures from the TestResultCollector and add them to failedTests .


XmlOutputter(const XmlOutputter& copy)

A copy constructor, scoped private to prevent its use.


void operator=(const XmlOutputter& copy)

A copy operator, scoped private to prevent its use.

Attributes


typedef map<Test *,TestFailure*> FailedTests

Defines the type FailedTests as a map of Test objects to TestFailure objects.


string m_encoding

The encoding type to be written in the XML prolog ( private ).


TestResultCollector *m_result

The TestResultCollector passed in the constructor ( private ).


ostream& m_stream

The output stream passed in the constructor ( private ).