RAPP Platform Wiki
v0.6.0
RAPP Platform is a collection of ROS nodes and back-end processes that aim to deliver ready-to-use generic services to robots
|
It is recommended to study on Rapp-Testing-Tools first.
Basic documentation on "**Developing Integration Tests**" can be found here.
A more-in-depth information on how to write your first integration test is presented here.
The template_test.py will be used as a reference.
Each integration test must have the following characteristics:
unittest.TestCase
class.If you are not familiar with the Python unit testing framework (unittest), start reading from there as the rapp_testing_tools is build ontop of it. Also, basic knowledge of using the python-rapp-platform-api is required.
So lets create a test class for testing the integration behaviour of the Face-Detection RAPP Platform service/functionality.
Copy the template_test.py
file and name it face_detection_tests.py
under the default_tests
directory
```bash $ cd ~/rapp_platform/rapp-platform-catkin-ws/src/rapp-platform/rapp_testing_tools/scripts/default_tests $ cp template_test.py face_detection_tests.py ```
Rename the test class to FaceDetectionTests
:
```python class FaceDetectionTests(unittest.TestCase):
def setUp(self): self.ch = RappPlatformAPI() rospack = rospkg.RosPack() self.pkgDir = rospack.get_path('rapp_testing_tools') def test_templateTest(self): self.assertEqual(1, 1)
```
Note that the setUp()
method instantiates a RappPlatformAPI() object for calling RAPP Platform Services.
As the FaceDetectionTests
class inherits from unittest.TestCase
, individual tests are defined with methods whose names start with the letters test
We will implement a test of performing face-detection on a single image file (Lenna.png). We assume that the image file was previously stored under the test_data
directory. So lets create a member method named test_lenna
This method will be responsible for loading the image file, call the RAPP Platform Service, through the API, and evaluate the results using unittest
assertions
```python class FaceDetectionTests(unittest.TestCase):
def setUp(self): self.ch = RappPlatformAPI() rospack = rospkg.RosPack() self.pkgDir = rospack.get_path('rapp_testing_tools') def test_lenna(self): self.assertEqual(1, 1) response = self.ch.faceDetection(imagepath) valid_faces = [{ 'up_left_point': {'y': 201.0, 'x': 213.0}, 'down_right_point': {'y': 378.0, 'x': 390.0} }] self.assertEqual(response['error'], u'') self.assertEqual(response['faces'], valid_faces)
```
The first assertion, `self.assertEqual(response['error'], u'')` evaluates that no error was reported from the RAPP Platform The second assertion evaluates the response from the FaceDetector.
The complete face_detection_tests.py source file is:
```python from os import path import timeit import unittest import rospkg
path = os.path.dirname(os.path.realpath(file))
from RappCloud import RappPlatformAPI
class FaceDetectionTests(unittest.TestCase):
def setUp(self): self.ch = RappPlatformAPI() rospack = rospkg.RosPack() self.pkgDir = rospack.get_path('rapp_testing_tools') def test_lenna(self): self.assertEqual(1, 1) response = self.ch.faceDetection(imagepath) valid_faces = [{ 'up_left_point': {'y': 201.0, 'x': 213.0}, 'down_right_point': {'y': 378.0, 'x': 390.0} }] self.assertEqual(response['error'], u'') self.assertEqual(response['faces'], valid_faces)
if name == "__main__": unittest.main() ```
Head to the scripts
directory and execute the rapp_run_test.py
script, giving as input argument the face_detection_tests.py
file to execute:
```bash $ cd ~/rapp_platform/rapp-platform-catkin-ws/src/rapp-platform/rapp_testing_tools/scripts $ ./rapp_run_test.py -i default_tests/face_detection_tests.py ```
On successful test execution, the output should be:
```bash
RAPP Platfrom Tests
Running face_detection_tests... Ran 1 tests in 0.383s Success ```
If an error occures on the RAPP Platform, the returned error message will be reported to the console output. For example, if the RAPP Platform Web Server was not previously launched properly, we should get a "Connection" error on the assertion of the error
property of the response:
```bash
RAPP Platfrom Tests
Running face_detection_tests... Ran 1 test in 0.078s Failed
Traceback (most recent call last): File "/home/rappuser/rapp_platform/rapp-platform-catkin-ws/src/rapp-platform/rapp_testing_tools/scripts/default_tests/face_detection_tests.py", line 61, in test_lenna self.assertEqual(response['error'], u'') AssertionError: 'Connection Error' != u''
Ran 1 test in 0.078s
FAILED (failures=1)
```