Loading...
Searching...
No Matches
robottestingframework::TestResult Class Reference

The TestResult class is used to deliver the test results including any error and failures produced by tests to any listener. More...

`#include <robottestingframework/TestResult.h>`

## Public Member Functions

| TestResult ()
| TestResult constructor.
virtual | ~TestResult ()
| TestResult destructor.
void | addListener (TestListener *listener)
| Adding a new listener.
void | removeListener (TestListener *listener)
| Remove a listener.
void | reset ()
| Clear the listener list.
void | addReport (const Test *test, TestMessage msg)
| This is called to report any arbitrary message from tests.
void | addError (const Test *test, TestMessage msg)
| This is called when an error occurred during test run.
void | addFailure (const Test *test, TestMessage msg)
| This is called when a failure occurred during test run.
void | startTest (const Test *test)
| This is called when a Test is started.
void | endTest (const Test *test)
| This is called when a Test is finished.
void | startTestSuite (const Test *test)
| This is called when a TestSuite is started.
void | endTestSuite (const Test *test)
| This is called when a TestSuite is finished.
void | startTestRunner ()
| This is called when the TestRunner is started.
void | endTestRunner ()
| This is called when the TestRunner is finished.

## Private Types

typedef std::set< TestListener * > | ListenerContainer
typedef std::set< TestListener * >::iterator | ListenerIterator

## Private Attributes

ListenerContainer | listeners

## Detailed Description

The TestResult class is used to deliver the test results including any error and failures produced by tests to any listener.

The listeneres can be added by `addListener`.

Here's an example of using a TestResult:

/*
* 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 <robottestingframework/ConsoleListener.h>
#include <robottestingframework/TestAssert.h>
#include <robottestingframework/TestCase.h>
#include <robottestingframework/TestResult.h>
#include <robottestingframework/TestResultCollector.h>
#include <cstdio>
#include <iostream>
using namespace robottestingframework;
class MyTest : public TestCase
{
public:
MyTest() :
TestCase("MyTest")
{
}
bool setup(int argc, char** argv) override
{
ROBOTTESTINGFRAMEWORK_TEST_REPORT("running MyTest::setup...");
return true;
}
void tearDown() override
{
ROBOTTESTINGFRAMEWORK_TEST_REPORT("running MyTest::teardown...");
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR("this is just for example!");
}
void run() override
{
ROBOTTESTINGFRAMEWORK_TEST_CHECK(2 < 3, "two is less than three");
ROBOTTESTINGFRAMEWORK_TEST_CHECK(2 == 3, "two is equal to three");
int a = 5;
int b = 3;
ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(a < b, Asserter::format("%d is not smaller than %d.", a, b));
}
};
int main(int argc, char** argv)
{
// create a test listener to collect the result
// and enable the verbose mode
ConsoleListener listener(true);
// create a collector to get computer readable
// test results
TestResultCollector collector;
// create a test result and add the listeners
TestResult result;
result.addListener(&listener);
result.addListener(&collector);
// calling a test case
MyTest atest;
atest.TestCase::run(result);
// return 0 if the test passed
// otherwise the number of failed test
return collector.failedCount();
}
ConsoleListener.h
TestAssert.h
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR
#define ROBOTTESTINGFRAMEWORK_ASSERT_ERROR(message)
Assertion with throwing error exception.
Definition TestAssert.h:90
ROBOTTESTINGFRAMEWORK_TEST_CHECK
#define ROBOTTESTINGFRAMEWORK_TEST_CHECK(condition, message)
ROBOTTESTINGFRAMEWORK_TEST_CHECK combines ROBOTTESTINGFRAMEWORK_TEST_REPORT and ROBOTTESTINGFRAMEWORK...
Definition TestAssert.h:188
ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE
#define ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(condition, message)
Conditional failure report.
Definition TestAssert.h:149
ROBOTTESTINGFRAMEWORK_TEST_REPORT
#define ROBOTTESTINGFRAMEWORK_TEST_REPORT(message)
Reporting a message to the TestResult.
Definition TestAssert.h:131
TestCase.h
TestResultCollector.h
TestResult.h
robottestingframework::ConsoleListener
class ConsoleListener listens to any messages reported by the tests during the test run,...
Definition ConsoleListener.h:39
robottestingframework::TestCase
The base class to implememnt a test case.
Definition TestCase.h:42
robottestingframework::TestCase::tearDown
virtual void tearDown()
tearDown is called after the test run
robottestingframework::TestCase::run
virtual void run()=0
run is called by the TestCase class if setup is successfull;
robottestingframework::TestCase::setup
virtual bool setup(int argc, char **argv)
setup is called before the test run.
robottestingframework::TestResultCollector
The TestResultCollector class can be used to store all the events issued by the test cases,...
Definition TestResultCollector.h:44
robottestingframework::TestResultCollector::failedCount
unsigned int failedCount()
failedCount gets the number of failed test cases.
robottestingframework::TestResult
The TestResult class is used to deliver the test results including any error and failures produced by...
Definition TestResult.h:44
robottestingframework::TestResult::addListener
void addListener(TestListener *listener)
Adding a new listener.
robottestingframework
Definition Arguments.h:25

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 TestResult.h.

## Member Typedef Documentation

## ListenerContainer

typedef std::set<TestListener*> robottestingframework::TestResult::ListenerContainer

private

Definition at line 45 of file TestResult.h.

## ListenerIterator

typedef std::set<TestListener*>::iterator robottestingframework::TestResult::ListenerIterator

private

Definition at line 46 of file TestResult.h.

## Constructor & Destructor Documentation

## TestResult()

robottestingframework::TestResult::TestResult | ( |  | ) |

TestResult constructor.

## ~TestResult()

virtual robottestingframework::TestResult::~TestResult | ( |  | ) |

virtual

TestResult destructor.

## Member Function Documentation

## addError()

void robottestingframework::TestResult::addError | ( | const Test * | test,
|  | TestMessage | msg )

This is called when an error occurred during test run.

Parameters

  test | pointer to the corresponding test
  msg | correspoinding error message

## addFailure()

void robottestingframework::TestResult::addFailure | ( | const Test * | test,
|  | TestMessage | msg )

This is called when a failure occurred during test run.

Parameters

  test | pointer to the corresponding test
  msg | correspoinding failure message

## addListener()

void robottestingframework::TestResult::addListener | ( | TestListener * | listener | ) |

Adding a new listener.

Parameters

  listener | pointer to a TestListener object

Examples
  simple.cpp, simple_collector.cpp, simple_fixture.cpp, simple_runner.cpp, simple_suite.cpp, and simple_web.cpp.

## addReport()

void robottestingframework::TestResult::addReport | ( | const Test * | test,
|  | TestMessage | msg )

This is called to report any arbitrary message from tests.

Parameters

  test | pointer to the corresponding test
  msg | correspoinding error message

## endTest()

void robottestingframework::TestResult::endTest | ( | const Test * | test | ) |

This is called when a Test is finished.

Parameters

  test | pointer to the corresponding test

## endTestRunner()

void robottestingframework::TestResult::endTestRunner | ( |  | ) |

This is called when the TestRunner is finished.

## endTestSuite()

void robottestingframework::TestResult::endTestSuite | ( | const Test * | test | ) |

This is called when a TestSuite is finished.

Parameters

  test | pointer to the corresponding test

## removeListener()

void robottestingframework::TestResult::removeListener | ( | TestListener * | listener | ) |

Remove a listener.

Parameters

  listener | pointer to a TestListener object

## reset()

void robottestingframework::TestResult::reset | ( |  | ) |

Clear the listener list.

## startTest()

void robottestingframework::TestResult::startTest | ( | const Test * | test | ) |

This is called when a Test is started.

Parameters

  test | pointer to the corresponding test

## startTestRunner()

void robottestingframework::TestResult::startTestRunner | ( |  | ) |

This is called when the TestRunner is started.

## startTestSuite()

void robottestingframework::TestResult::startTestSuite | ( | const Test * | test | ) |

This is called when a TestSuite is started.

Parameters

  test | pointer to the corresponding test

## Member Data Documentation

## listeners

ListenerContainer robottestingframework::TestResult::listeners

private

Definition at line 133 of file TestResult.h.

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

- src/robottestingframework/include/robottestingframework/TestResult.h