← Back to search

[ROS in 5 mins] 054 - How to Unit Test loading a ROS Param

The Construct Robotics Institute 8:42

1,871 views · 18 likes Watch on YouTube ↗

Hi all,

welcome to this "ROS In 5 Minutes" videos series.

In today's videos we are going to learn how to run a Unit Test which ensures a parameter has been loaded on the ROS Parameter Server.

But before we start, if you want to Learn ROS Fast, remember to take one of the following courses:

ROS In 5 Days (Python) - http://bit.ly/2K9PqDf
ROS In 5 Days (C++) - http://bit.ly/2KhSddT

In the video we used the following commands to create the structure of our package:

mkdir ~/catkin_ws/src -p
cd ~/catkin_ws/src
catkin_create_pkg tutorial rospy
cd tutorial/
mkdir launch
touch launch/load_params.launch


In order to find a yaml file to be loaded, we used:
find /opt/ros/kinetic/ -name *.yaml | head

With that command we found the file below:
/opt/ros/kinetic/share/nodelet_tutorial_math/plus_default.yaml


That file has a parameter called "value".

We then created a test file:
mkdir test
cd test
touch test_params.py
chmod +x test_params.py

The content of our test_params.py was:

#! /usr/bin/env python

import unittest
import rospy
import rostest


class MyTestCase(unittest.TestCase):
def test_param_loaded(self):
value = rospy.get_param('/value', None)
self.assertIsNotNone(value)


if __name__ == '__main__':
rostest.rosrun('tutorial', 'test_params', MyTestCase)


And to run the test we ran:
rostest tutorial load_params.test


That is all for today. Remember that we have a detailed post showing all the commands used on the video in the following address: http://www.theconstructsim.com/ros-5-mins-054-unit-test-loading-ros-param/

Whether you like the video or not, please leave a comment on the comments section below,
so that we can interact and learn from each other.

Category (YouTube): Science & Technology

Playback is via YouTube's official embedded player. Data from YouTube; Exumo is not affiliated with YouTube.