[ROS in 5 mins] 055 – Four different ways of testing your ROS python code

[ROS in 5 mins] 055 - Four different ways of testing your ROS python code

Written by Ruben Alves

03/12/2018

Welcome to this “ROS In 5 Minutes” videos series.

In today’s videos we are going to learn 4 different ways of testing your ROS code written in python.

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

In order to create our package we have used the following commands:

mkdir ~/catkin_ws/src -p
cd ~/catkin_ws/src
catkin_create_pkg tutorial rospy
cd tutorial/
mkdir test
cd test/
touch test_code.py
chmod +x test_code.py
ls

The content of our test_code.py file is:

#! /usr/bin/env python

import unittest
import rostest

class MyTestCase(unittest.TestCase):

def test_whatever(self):
pass

if __name__ == “__main__”:
rostest.rosrun(‘tutorial’, ‘test_code’, MyTestCase)

The first way of executing it is by calling it directly:
./test_code.py

The second way is using a .test file:
roscd tutorial
mkdir launch
cd launch/
touch test_code.test

After filling that file we call it with:
rostest tutorial test_code.test

The 3rd way of executing is by adding the line below to our CMakeLists.txt file:
catkin_add_nosetests(test/test_code.py)

and calling:
cd ~/catkin_ws/
catkin_make run_tests

And the 4th way is by adding the lines below to our CMakeLists.txt file (remove to remove the line added on the 3rd way, otherwise
your test will be executed twice, wasting time):

find_package(rostest REQUIRED)
add_rostest(launch/test_code.test)

and executing:
cd ~/catkin_ws/
catkin_make run_tests

That is all for today.

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.

Masterclass 2023 batch2 blog banner

Check Out These Related Posts

0 Comments

Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This