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

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

#include <robottestingframework/TestSuite.h>

+ Inheritance diagram for robottestingframework::TestSuite:

Public Member Functions

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

Protected Member Functions

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

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

Testcurrent
 
TestResultresult
 
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 <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 collect the result
ConsoleListener listener(false);
// create a collector to get computer readable
// test results
// create a test result and add the listeners
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();
}
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

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

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
nameThe 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
manageran instance of FixtureManager
Examples:
simple_fixture.cpp.

◆ addTest()

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

Adding a new test.

Parameters
testpointer to a Test object
Examples:
simple_collector.cpp, simple_fixture.cpp, simple_suite.cpp, and simple_web.cpp.

◆ fixtureCollapsed()

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

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
reasonAn 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 ( )
overridevirtual

interrupt interrupts the current test run

Reimplemented from robottestingframework::Test.

◆ removeTest()

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

Remove a test.

Parameters
testpointer to a Test object

◆ reset()

void robottestingframework::TestSuite::reset ( )

Clear the test list.

◆ run()

void robottestingframework::TestSuite::run ( TestResult rsl)
overridevirtual

the main caller of a TestSuite inherited from Test Class.

Parameters
resultan instance of a TestResult to collect the result of the test.

Implements robottestingframework::Test.

◆ setup()

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

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
overridevirtual

succeeded

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

Implements robottestingframework::Test.

◆ tearDown()

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

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: