RobotTestingFramework  2.0.1
Robot Testing Framework
Public Member Functions | Private Attributes | List of all members
robottestingframework::TestCase Class Referenceabstract

The base class to implememnt a test case. More...

#include <robottestingframework/TestCase.h>

+ Inheritance diagram for robottestingframework::TestCase:

Public Member Functions

 TestCase (std::string name, std::string param="")
 TestCase constructor. More...
 
virtual ~TestCase ()
 TestCase destructor. More...
 
virtual bool setup (int argc, char **argv)
 setup is called before the test run. More...
 
virtual void tearDown ()
 tearDown is called after the test run More...
 
virtual void run ()=0
 run is called by the TestCase class if setup is successfull; More...
 
void interrupt () override
 interrupt interrupts the current test run More...
 
void run (TestResult &rsl) override
 the main caller of a TestCase inherited from Test Class. More...
 
bool succeeded () const override
 succeeded More...
 
void failed ()
 failed Sets the test successful flag to false which indicates that the test was not successful. More...
 
TestResultgetResult ()
 getResult Returns an instance of TestResult if run(TestResult &result) has been already called by a TestRunner More...
 
void setParam (const std::string param)
 setParam Sets the optional parameters of the test. More...
 
std::string getParam ()
 getParam gets the original paramter string which is set for the test case More...
 
void setEnvironment (const std::string environment)
 setEnvironment Optioanlly specifies the environment in which the test case is executed. More...
 
std::string getEnvironment ()
 getParam gets the environment string which is set for the test case More...
 
void setRepetition (unsigned int rep)
 setRepetition sets the run repetition by default the run() method is called only once; The number of test runs (e.g., for stress testing) can be set using this function. More...
 
unsigned int getRepetition ()
 getRepetition gets the tun repetition 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...
 

Private Attributes

std::string param
 
std::string environment
 
TestResultresult
 
bool successful
 
bool interrupted
 
unsigned int repetition
 

Additional Inherited Members

- Protected Member Functions inherited from robottestingframework::Test
void setName (std::string name)
 setName setting the test name More...
 

Detailed Description

The base class to implememnt a test case.

The user defined test cases should be inherited from TestCase class and the run() method must be overriden. The 'setup(int argc, char** argv)' and tearDown() can be also inherited to implement any initialization or finalization of the test case.

Here's an example of using a TestCase:

/*
* 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
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 41 of file TestCase.h.

Constructor & Destructor Documentation

◆ TestCase()

robottestingframework::TestCase::TestCase ( std::string  name,
std::string  param = "" 
)

TestCase constructor.

Parameters
nameThe TestCase name
paramThe optional parameters for the test case

◆ ~TestCase()

virtual robottestingframework::TestCase::~TestCase ( )
virtual

TestCase destructor.

Member Function Documentation

◆ failed()

void robottestingframework::TestCase::failed ( )

failed Sets the test successful flag to false which indicates that the test was not successful.

◆ getEnvironment()

std::string robottestingframework::TestCase::getEnvironment ( )

getParam gets the environment string which is set for the test case

Returns
A environment string

◆ getParam()

std::string robottestingframework::TestCase::getParam ( )

getParam gets the original paramter string which is set for the test case

Returns
a string paramter

◆ getRepetition()

unsigned int robottestingframework::TestCase::getRepetition ( )

getRepetition gets the tun repetition

Returns
the number of repetitions

◆ getResult()

TestResult* robottestingframework::TestCase::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::TestCase::interrupt ( )
overridevirtual

interrupt interrupts the current test run

Reimplemented from robottestingframework::Test.

◆ run() [1/2]

virtual void robottestingframework::TestCase::run ( )
pure virtual

◆ run() [2/2]

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

the main caller of a TestCase inherited from Test Class.

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

Implements robottestingframework::Test.

◆ setEnvironment()

void robottestingframework::TestCase::setEnvironment ( const std::string  environment)

setEnvironment Optioanlly specifies the environment in which the test case is executed.

The TestCase class does not make any use of it. The environment can be used in the implementation of the test cases to know in which setup (e.g., simulation, real world environment) the test case is employed.

Parameters
environmentThe optional environment string

◆ setParam()

void robottestingframework::TestCase::setParam ( const std::string  param)

setParam Sets the optional parameters of the test.

The parameter string is parsed into (argc/argv) format and will be passed to the test case using setup(int argc, char** argv).

Parameters
paramthe paramter string

◆ setRepetition()

void robottestingframework::TestCase::setRepetition ( unsigned int  rep)

setRepetition sets the run repetition by default the run() method is called only once; The number of test runs (e.g., for stress testing) can be set using this function.

Parameters
repnumber of repetitions

◆ setup()

virtual bool robottestingframework::TestCase::setup ( int  argc,
char **  argv 
)
virtual

setup is called before the test run.

Note
the first value in argv is the name of the current testcases
Parameters
argcThe number of the pasred argument from string paramter
argvThe arguments which is parsed using string paramter
Returns
true or false depending of the test initialization

Reimplemented in robottestingframework::plugin::LuaPluginLoaderImpl, robottestingframework::plugin::RubyPluginLoaderImpl, and robottestingframework::plugin::PythonPluginLoaderImpl.

◆ succeeded()

bool robottestingframework::TestCase::succeeded ( ) const
overridevirtual

succeeded

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

Implements robottestingframework::Test.

◆ tearDown()

virtual void robottestingframework::TestCase::tearDown ( )
virtual

Member Data Documentation

◆ environment

std::string robottestingframework::TestCase::environment
private

Definition at line 158 of file TestCase.h.

◆ interrupted

bool robottestingframework::TestCase::interrupted
private

Definition at line 161 of file TestCase.h.

◆ param

std::string robottestingframework::TestCase::param
private

Definition at line 157 of file TestCase.h.

◆ repetition

unsigned int robottestingframework::TestCase::repetition
private

Definition at line 162 of file TestCase.h.

◆ result

TestResult* robottestingframework::TestCase::result
private

Definition at line 159 of file TestCase.h.

◆ successful

bool robottestingframework::TestCase::successful
private

Definition at line 160 of file TestCase.h.


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