RobotTestingFramework  2.0.1
Robot Testing Framework
Public Types | Public Member Functions | Private Attributes | List of all members
robottestingframework::TestResultCollector Class Reference

The TestResultCollector class can be used to store all the events issued by the test cases, suites and runner during the test run. More...

#include <robottestingframework/TestResultCollector.h>

+ Inheritance diagram for robottestingframework::TestResultCollector:

Public Types

typedef std::vector< ResultEvent * > EventResultContainer
 
typedef std::vector< ResultEvent * >::iterator EventResultIterator
 

Public Member Functions

 TestResultCollector ()
 TestResultCollector constructor. More...
 
 ~TestResultCollector () override
 TestResultCollector destructor. More...
 
void reset ()
 reset clear the results More...
 
unsigned int testCount ()
 testCount gets the number of test cases. More...
 
unsigned int failedCount ()
 failedCount gets the number of failed test cases. More...
 
unsigned int passedCount ()
 passedCount gets the number of passed test cases. More...
 
unsigned int suiteCount ()
 suiteCount gets the number of test suites. More...
 
unsigned int failedSuiteCount ()
 failedCount gets the number of failed test suites. More...
 
unsigned int passedSuiteCount ()
 passedCount gets the number of passed test suites. More...
 
EventResultContainergetResults ()
 getResults return any result event caught by the TestResultCollector. More...
 
void addReport (const Test *test, TestMessage msg) override
 This is called to report any arbitrary message from tests. More...
 
void addError (const Test *test, TestMessage msg) override
 This is called when an error occurred during test run. More...
 
void addFailure (const Test *test, TestMessage msg) override
 This is called when a failure occurred during test run. More...
 
void startTest (const Test *test) override
 This is called when a Test is started. More...
 
void endTest (const Test *test) override
 This is called when a Test is finished. More...
 
void startTestSuite (const Test *test) override
 This is called when a TestSuite is started. More...
 
void endTestSuite (const Test *test) override
 This is called when a TestSuite is finished. More...
 
- Public Member Functions inherited from robottestingframework::TestListener
 TestListener ()=default
 TestListener constructor. More...
 
virtual ~TestListener ()=default
 TestListener destructor. More...
 
virtual void startTestRunner ()
 This is called when the TestRunner is started. More...
 
virtual void endTestRunner ()
 This is called when the TestRunner is finished. More...
 

Private Attributes

EventResultContainer events
 
unsigned int nTests
 
unsigned int nFailures
 
unsigned int nPasses
 
unsigned int nTestSuites
 
unsigned int nSuiteFailures
 
unsigned int nSuitePasses
 

Detailed Description

The TestResultCollector class can be used to store all the events issued by the test cases, suites and runner during the test run.

The collected events later can be used by a proper result formatter to be exported as HTML, XML or other desired formats.

Here's an example of using a TestResultCollector:

/*
* Robot Testing Framework
*
* Copyright (C) 2015-2019 Istituto Italiano di Tecnologia (IIT)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <cstdio>
using namespace robottestingframework;
class MyTest1 : public TestCase
{
public:
MyTest1() :
TestCase("MyTest1")
{
}
void run() override
{
ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(3 < 5, "is not smaller");
}
};
class MyTest2 : public TestCase
{
public:
MyTest2() :
TestCase("MyTest2")
{
}
void run() override
{
ROBOTTESTINGFRAMEWORK_TEST_REPORT("testing equality");
ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(5 == 3, "are not equal");
}
};
int main(int argc, char** argv)
{
// create a test listener to print out the result
ConsoleListener listener(false);
// create a test result collector to collect the result
// create a test result and add the listeners
TestResult result;
result.addListener(&listener);
result.addListener(&collector);
// create a test suite and the test cases
TestSuite suite("MyTestSuite");
MyTest1 test1;
MyTest2 test2;
suite.addTest(&test1);
suite.addTest(&test2);
// create a test runner
TestRunner runner;
runner.addTest(&suite);
runner.run(result);
// print out some simple statistics
printf("\n-------- results ---------\n");
printf("Total number of tests : %d\n", collector.testCount());
printf("Number of passed tests: %d\n", collector.passedCount());
printf("Number of failed tests: %d\n", collector.failedCount());
// store the results in a text file
TextOutputter outputter(collector);
outputter.write("./result.txt", true);
// return the number of failed tests
return collector.failedCount();
}
Examples:
simple.cpp, simple_collector.cpp, simple_fixture.cpp, simple_runner.cpp, simple_suite.cpp, and simple_web.cpp.

Definition at line 43 of file TestResultCollector.h.

Member Typedef Documentation

◆ EventResultContainer

Definition at line 46 of file TestResultCollector.h.

◆ EventResultIterator

Definition at line 47 of file TestResultCollector.h.

Constructor & Destructor Documentation

◆ TestResultCollector()

robottestingframework::TestResultCollector::TestResultCollector ( )

TestResultCollector constructor.

◆ ~TestResultCollector()

robottestingframework::TestResultCollector::~TestResultCollector ( )
override

TestResultCollector destructor.

Member Function Documentation

◆ addError()

void robottestingframework::TestResultCollector::addError ( const Test test,
TestMessage  msg 
)
overridevirtual

This is called when an error occurred during test run.

Parameters
testpointer to the corresponding test
msgcorrespoinding error message

Reimplemented from robottestingframework::TestListener.

◆ addFailure()

void robottestingframework::TestResultCollector::addFailure ( const Test test,
TestMessage  msg 
)
overridevirtual

This is called when a failure occurred during test run.

Parameters
testpointer to the corresponding test
msgcorrespoinding failure message

Reimplemented from robottestingframework::TestListener.

◆ addReport()

void robottestingframework::TestResultCollector::addReport ( const Test test,
TestMessage  msg 
)
overridevirtual

This is called to report any arbitrary message from tests.

Parameters
testpointer to the corresponding test
msgcorrespoinding error message

Reimplemented from robottestingframework::TestListener.

◆ endTest()

void robottestingframework::TestResultCollector::endTest ( const Test test)
overridevirtual

This is called when a Test is finished.

Parameters
testpointer to the corresponding test

Reimplemented from robottestingframework::TestListener.

◆ endTestSuite()

void robottestingframework::TestResultCollector::endTestSuite ( const Test test)
overridevirtual

This is called when a TestSuite is finished.

Parameters
testpointer to the corresponding test

Reimplemented from robottestingframework::TestListener.

◆ failedCount()

unsigned int robottestingframework::TestResultCollector::failedCount ( )

failedCount gets the number of failed test cases.

The test suites are not counted.

Returns
the number of failed tests.
Examples:
simple.cpp, simple_collector.cpp, simple_fixture.cpp, simple_runner.cpp, simple_suite.cpp, and simple_web.cpp.

◆ failedSuiteCount()

unsigned int robottestingframework::TestResultCollector::failedSuiteCount ( )

failedCount gets the number of failed test suites.

Returns
the number of failed test suites.

◆ getResults()

EventResultContainer& robottestingframework::TestResultCollector::getResults ( )

getResults return any result event caught by the TestResultCollector.

The events are stored in the ResultEvent format which can be type casted to any subtype event such as ResultEventReport, ResultEventError and etc. to indicate the actual type of the events.

Returns
a EventResultContainer of the events

◆ passedCount()

unsigned int robottestingframework::TestResultCollector::passedCount ( )

passedCount gets the number of passed test cases.

The test suites are not counted.

Returns
the number of passed tests.
Examples:
simple_collector.cpp.

◆ passedSuiteCount()

unsigned int robottestingframework::TestResultCollector::passedSuiteCount ( )

passedCount gets the number of passed test suites.

Returns
the number of passed test suites.

◆ reset()

void robottestingframework::TestResultCollector::reset ( )

reset clear the results

◆ startTest()

void robottestingframework::TestResultCollector::startTest ( const Test test)
overridevirtual

This is called when a Test is started.

Parameters
testpointer to the corresponding test

Reimplemented from robottestingframework::TestListener.

◆ startTestSuite()

void robottestingframework::TestResultCollector::startTestSuite ( const Test test)
overridevirtual

This is called when a TestSuite is started.

Parameters
testpointer to the corresponding test

Reimplemented from robottestingframework::TestListener.

◆ suiteCount()

unsigned int robottestingframework::TestResultCollector::suiteCount ( )

suiteCount gets the number of test suites.

Returns
the number of test suites

◆ testCount()

unsigned int robottestingframework::TestResultCollector::testCount ( )

testCount gets the number of test cases.

The test suites are not counted.

Returns
the number of tests
Examples:
simple_collector.cpp.

Member Data Documentation

◆ events

EventResultContainer robottestingframework::TestResultCollector::events
private

Definition at line 161 of file TestResultCollector.h.

◆ nFailures

unsigned int robottestingframework::TestResultCollector::nFailures
private

Definition at line 163 of file TestResultCollector.h.

◆ nPasses

unsigned int robottestingframework::TestResultCollector::nPasses
private

Definition at line 164 of file TestResultCollector.h.

◆ nSuiteFailures

unsigned int robottestingframework::TestResultCollector::nSuiteFailures
private

Definition at line 166 of file TestResultCollector.h.

◆ nSuitePasses

unsigned int robottestingframework::TestResultCollector::nSuitePasses
private

Definition at line 167 of file TestResultCollector.h.

◆ nTests

unsigned int robottestingframework::TestResultCollector::nTests
private

Definition at line 162 of file TestResultCollector.h.

◆ nTestSuites

unsigned int robottestingframework::TestResultCollector::nTestSuites
private

Definition at line 165 of file TestResultCollector.h.


The documentation for this class was generated from the following file: