RobotTestingFramework
2.0.1
Robot Testing Framework
|
Test cases can be written as dynamic loadable libraries (e.g., .so, .dll) to be loaded and executed as separate plug-ins. This allows to have a simple test runner which loads and run the tests at run time without any needs to recompile the test runner. Using a simple example, we show how this can be done.
'examples/plugin'
folder within the Robot Testing Framework project directory. To compile it, you just need to enable the BUILD_EXAMPLES=ON
flag of the CMake (if it is not already enabled) and build the Robot Testing Framework.
You do not need any external library to use the plug-ins. All you need is to simply enable the plug-in system in the Robot Testing Framework and recompile it if it is not already enabled (it should be enabled by default).
$ cd robot-testing-framework/build $ cmake ../ -DENABLE_PLUGIN=ON
Create a class which inherited from the TestCase class. Override the run()
method and/or setup(int argc, char** argv)
, tearDown()
if needed. The parameters set for the test case using robottestingframework::TestCase::setParam
are parsed into standard
format and are passed to the (int argc, char**argv)
setup
method. The original string parameter is also accessible using robottestingframework::TestCase::getParam
. Here is an example:
Implement the test body in the run()
method and add use the 'PREPARE_PLUGIN
(...)' macro to prepare the plug-in. The macro implements the necessary functionalities to make your test class be accessible from a shared library.
robottestingframework-testrunner
utility (see Running test case plug-ins using robottestingframework-testrunner) already implemented in Robot Testing Framework which does the job for you. However, the following example is just for your reference and to understand better how a test plug-ing can be loaded and executed from the code.Your plug-in is ready and can be compiled and built. Before doing, that we show how to use robottestingframework::DllPluginLoader
to develop a simple test runner for loading the plug-in and running the test. It is quite simple. First create an instance of robottestingframework::plugin::DllPluginLoader
class and call its open()
method with the plug-in library (.dll, .so, ...) filename as its paramter. The robottestingframework::plugin::DllPluginLoader
loads the library and return a pointer to the robottestingframework::TestCase
implemented into the plug-in. If the plug-in cannot be loaded or it is not an Robot Testing Framework plug-in file, the robottestingframework::plugin::DllPluginLoader::open()
returns a null pointer and the error message can be gotten using robottestingframework::plugin::DllPluginLoader::getLastError()
. When you have an instance of your test case, it can be used to run the test as usual (see Some examples if you are not familiar with running a test case). In the following example we use a robottestingframework::TestRunner
to execute our test:
Now you can compile and build the plug-in and the runner. There is a CMake file in the examples/plugin
folder which helps you to compile and build your test plugin and the simple test runner. Make sure that RobotTestingFramework_DIR
environment variable is correctly set to point your Robot Testing Framework build or installed directory so that CMake can find the required modules to configure the project.
Now you can build and run the test as follows:
$ cd examples/plugin; mkdir build $ cd build; cmake ../; make; $ ./simple_run libmytest.so Loading the plugin... Starting test runner. Test case MyTest started... [INFO] (MyTest) reports: running MyTest::setup... [INFO] (MyTest) reports: testing integers [FAIL] (MyTest) checking (a<b): 5 is not smaller than 3. [INFO] (MyTest) reports: running MyTest::teardown... [ERROR] (MyTest) asserts error with exception: this is just for example! Test case MyTest failed! Ending test runner.