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

The TestSuite holds a group of tests. More...

`#include <robottestingframework/TestSuite.h>`

Inheritance diagram for robottestingframework::TestSuite:
[legend]

## Public Member Functions

| TestSuite (std::string name)
| TestSuite constructor.
virtual | ~TestSuite ()
| TestSuite destructor.
void | addTest (Test *test)
| Adding a new test.
void | removeTest (Test *test)
| Remove a test.
void | reset ()
| Clear the test list.
void | addFixtureManager (FixtureManager *manager)
| addFixtureManager add a fixture manager for the current test suite.
void | fixtureCollapsed (TestMessage reason) override
| fixtureCollapsed is called by a fixture manager (if it is already setup) to inform the test suite that the corresponding fixture has been collapsed.
void | run (TestResult &rsl) override
| the main caller of a TestSuite inherited from Test Class.
void | interrupt () override
| interrupt interrupts the current test run
bool | succeeded () const override
| succeeded
TestResult * | getResult ()
| getResult returns an instance of TestResult if run(TestResult &result) has been already called by a TestRunner
std::size_t | size () const
| returns the number of tests in this suite
Public Member Functions inherited from robottestingframework::Test
| Test (std::string name, std::string description="")
| Test constructor.
virtual | ~Test ()
| Test destructor.
const std::string | getName () const
| getName Getting test name.
const std::string | getDescription () const
| getDescription Getting test description
void | setDescription (const std::string description)
| setDescription Sets an optional string which describes the test.

## Protected Member Functions

virtual bool | setup ()
| setup is called before the test run
virtual void | tearDown ()
| tearDown is called after the test run
Protected Member Functions inherited from robottestingframework::Test
void | setName (std::string name)
| setName setting the test name

## Private Types

typedef std::vector< Test * > | TestContainer
typedef std::vector< Test * >::iterator | TestIterator
typedef std::vector< FixtureManager * > | FixtureContainer
typedef std::vector< FixtureManager * >::iterator | FixtureIterator
typedef std::vector< FixtureManager * >::reverse_iterator | FixtureRIterator

## Private Attributes

Test * | current
TestResult * | result
bool | successful
bool | fixtureOK
bool | interrupted
TestMessage | fixtureMessage
FixtureContainer | fixtureManagers
TestContainer | tests

## Detailed Description

The TestSuite holds a group of tests.

When the `run()` method of a TestSuite is called, it executes all its tests. A TestSuite can also has a FixtureManager. In this case, it calls the `setup()` method of FixtureManager to setup any fixture which is required for the tests before executing the tests. After running all the tests, the `tearDown()` method of the FixtureManager is called to tear down the fixture.

The `fixtureCollapsed` method is used by a fixture manager to inform the test suite that the corresponding fixture has been collapsed. In this case, an exception is thrown by the TestSuite and the remaining tests will not be executed any more. This method can be also overriden by a subclass if any specific action is required to be taken (such as retrying to setup the fixture and runing the reamining tests) upon collapsing the fixture.

Here's an example of using a TestSuite:

/*
* 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 <robottestingframework/TestRunner.h>
#include <robottestingframework/TestSuite.h>
#include <cstdio>
using namespace robottestingframework;
class MyTest1 : public TestCase
{
public:
MyTest1() :
TestCase("MyTest1")
{
}
void run() override
{
ROBOTTESTINGFRAMEWORK_TEST_REPORT("testing smaller");
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 collect the result
ConsoleListener listener(false);
// 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);
// 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);
// return the number of failed tests
return collector.failedCount();
}
ConsoleListener.h
TestAssert.h
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
TestRunner.h
TestSuite.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::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::TestRunner
The TestRunner class runs the tests added as TestCase or TestSuite.
Definition TestRunner.h:42
robottestingframework::TestRunner::run
void run(TestResult &result)
Run all the tests in the list.
robottestingframework::TestRunner::addTest
void addTest(Test *test)
Adding a new test.
robottestingframework::TestSuite
The TestSuite holds a group of tests.
Definition TestSuite.h:55
robottestingframework::TestSuite::result
TestResult * result
Definition TestSuite.h:155
robottestingframework
Definition Arguments.h:25

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

Definition at line 52 of file TestSuite.h.

## Member Typedef Documentation

## FixtureContainer

typedef std::vector<FixtureManager*> robottestingframework::TestSuite::FixtureContainer

private

Definition at line 59 of file TestSuite.h.

## FixtureIterator

typedef std::vector<FixtureManager*>::iterator robottestingframework::TestSuite::FixtureIterator

private

Definition at line 60 of file TestSuite.h.

## FixtureRIterator

typedef std::vector<FixtureManager*>::reverse_iterator robottestingframework::TestSuite::FixtureRIterator

private

Definition at line 61 of file TestSuite.h.

## TestContainer

typedef std::vector<Test*> robottestingframework::TestSuite::TestContainer

private

Definition at line 57 of file TestSuite.h.

## TestIterator

typedef std::vector<Test*>::iterator robottestingframework::TestSuite::TestIterator

private

Definition at line 58 of file TestSuite.h.

## Constructor & Destructor Documentation

## TestSuite()

robottestingframework::TestSuite::TestSuite | ( | std::string | name | ) |

TestSuite constructor.

Parameters

  name | The TestSuite name

## ~TestSuite()

virtual robottestingframework::TestSuite::~TestSuite | ( |  | ) |

virtual

TestSuite destructor.

## Member Function Documentation

## addFixtureManager()

void robottestingframework::TestSuite::addFixtureManager | ( | FixtureManager * | manager | ) |

addFixtureManager add a fixture manager for the current test suite.

Parameters

  manager | an instance of FixtureManager

## addTest()

void robottestingframework::TestSuite::addTest | ( | Test * | test | ) |

Adding a new test.

Parameters

  test | pointer to a Test object

## fixtureCollapsed()

void robottestingframework::TestSuite::fixtureCollapsed | ( | TestMessage | reason | ) |

override virtual

fixtureCollapsed is called by a fixture manager (if it is already setup) to inform the test suite that the corresponding fixture has been collapsed.

Parameters

  reason | An error message indicates the reason for collapsing the fixture.

Implements robottestingframework::FixtureEvents.

## getResult()

TestResult * robottestingframework::TestSuite::getResult | ( |  | ) |

getResult returns an instance of TestResult if run(TestResult &result) has been already called by a TestRunner

Returns
  an instance of TestResult

## interrupt()

void robottestingframework::TestSuite::interrupt | ( |  | ) |

override virtual

interrupt interrupts the current test run

Reimplemented from robottestingframework::Test.

## removeTest()

void robottestingframework::TestSuite::removeTest | ( | Test * | test | ) |

Remove a test.

Parameters

  test | pointer to a Test object

## reset()

void robottestingframework::TestSuite::reset | ( |  | ) |

Clear the test list.

## run()

void robottestingframework::TestSuite::run | ( | TestResult & | rsl | ) |

override virtual

the main caller of a TestSuite inherited from Test Class.

Parameters

  result | an instance of a TestResult to collect the result of the test.

Implements robottestingframework::Test.

## setup()

virtual bool robottestingframework::TestSuite::setup | ( |  | ) |

protected virtual

setup is called before the test run

Returns
  true or false depending of the test initialization

## size()

std::size_t robottestingframework::TestSuite::size | ( |  | ) | const

returns the number of tests in this suite

Returns
  the number of tests in this suite

## succeeded()

bool robottestingframework::TestSuite::succeeded | ( |  | ) | const

override virtual

succeeded

Returns
  true or false representing whether the test was successful or not.

Implements robottestingframework::Test.

## tearDown()

virtual void robottestingframework::TestSuite::tearDown | ( |  | ) |

protected virtual

tearDown is called after the test run

## Member Data Documentation

## current

Test* robottestingframework::TestSuite::current

private

Definition at line 154 of file TestSuite.h.

## fixtureManagers

FixtureContainer robottestingframework::TestSuite::fixtureManagers

private

Definition at line 160 of file TestSuite.h.

## fixtureMessage

TestMessage robottestingframework::TestSuite::fixtureMessage

private

Definition at line 159 of file TestSuite.h.

## fixtureOK

bool robottestingframework::TestSuite::fixtureOK

private

Definition at line 157 of file TestSuite.h.

## interrupted

bool robottestingframework::TestSuite::interrupted

private

Definition at line 158 of file TestSuite.h.

## result

TestResult* robottestingframework::TestSuite::result

private

Definition at line 155 of file TestSuite.h.

## successful

bool robottestingframework::TestSuite::successful

private

Definition at line 156 of file TestSuite.h.

## tests

TestContainer robottestingframework::TestSuite::tests

private

Definition at line 161 of file TestSuite.h.

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

- src/robottestingframework/include/robottestingframework/TestSuite.h