RobotTestingFramework  2.0.1
Robot Testing Framework
Public Member Functions | Private Types | Private Attributes | List of all members
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. More...
 
virtual ~TestResult ()
 TestResult destructor. More...
 
void addListener (TestListener *listener)
 Adding a new listener. More...
 
void removeListener (TestListener *listener)
 Remove a listener. More...
 
void reset ()
 Clear the listener list. More...
 
void addReport (const Test *test, TestMessage msg)
 This is called to report any arbitrary message from tests. More...
 
void addError (const Test *test, TestMessage msg)
 This is called when an error occurred during test run. More...
 
void addFailure (const Test *test, TestMessage msg)
 This is called when a failure occurred during test run. More...
 
void startTest (const Test *test)
 This is called when a Test is started. More...
 
void endTest (const Test *test)
 This is called when a Test is finished. More...
 
void startTestSuite (const Test *test)
 This is called when a TestSuite is started. More...
 
void endTestSuite (const Test *test)
 This is called when a TestSuite is finished. More...
 
void startTestRunner ()
 This is called when the TestRunner is started. More...
 
void endTestRunner ()
 This is called when the TestRunner is finished. More...
 

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 <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
// 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();
}
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

Definition at line 45 of file TestResult.h.

◆ ListenerIterator

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
testpointer to the corresponding test
msgcorrespoinding error message

◆ addFailure()

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

This is called when a failure occurred during test run.

Parameters
testpointer to the corresponding test
msgcorrespoinding failure message

◆ addListener()

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

Adding a new listener.

Parameters
listenerpointer 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
testpointer to the corresponding test
msgcorrespoinding error message

◆ endTest()

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

This is called when a Test is finished.

Parameters
testpointer 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
testpointer to the corresponding test

◆ removeListener()

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

Remove a listener.

Parameters
listenerpointer 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
testpointer 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
testpointer 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: