ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

rostest: specifying a single test case

asked 2018-03-12 11:52:10 -0500

knxa gravatar image

updated 2018-03-13 05:22:29 -0500

How do I tell rostest to only run a single specific test method in a python unittest.TestCase class? I can execute the full test suite with:

rostest foo foo.test

The tests are defined in a file test/rostest_foo.py, how do I run only the test method test_a in class TestFoo? Any command line arguments to rostest?

My test classes are looking like this:

#!/usr/bin/env python

import rospy
import unittest

class TestFoo(unittest.TestCase):

    def test_a(self):
        self.assertEqual(2+3, 5)

if __name__ == '__main__':
    import rostest
    rospy.init_node('TestFoo', anonymous=True)
    rostest.rosrun('foo', 'TestFoo', TestFoo)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2022-12-28 05:39:30 -0500

knxa gravatar image

Answering my own old question:

in ROS melodic you can use a string describing a specific test like this:

rostest.rosrun('foo', 'TestFoo', '__main__.TestFoo.test_a')

... and of course that string may come from command line arguments.

edit flag offensive delete link more
0

answered 2022-04-19 10:16:35 -0500

tahsinkose gravatar image

rostest does not currently have a way to specify filters at the command line. Nevertheless, if you were using C++, you could specify gtest filters as args for your test node. E.g:

<launch>
     ...
     <test test-name="foo" pkg="foo" type="foo" args="--gtest-filter ..."/>
</launch>

Python's unittest probably has a similar structure, where you can pass filters to the test node as arguments.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-03-12 11:52:10 -0500

Seen: 673 times

Last updated: Dec 28 '22