Ask Your Question
1

Any way to use a TestSuite (instead a TestCase) with rostest?

asked 2014-01-27 01:47:37 -0500

updated 2014-06-02 03:58:59 -0500

UPDATE: See rosticket #423

I am using rostest under rosbuild to create unittests with Python.

I understand how to create unittests and rostests, for instance, to create a TestsCase and call it from rostest.rosrun:

import unittest
class MyFirstTestCase(unittest.TestCase):
    def setUp(self):
        # SetUp code

    def tearDown(self):
        # TearDown code

    def test_something(self):
        # some test code

    def test_more_stuff(self):
        # more test code


if __name__ == '__main__':
    import rostest
    rostest.rosrun('my_package', 'test_my_first_test_case', MyFirstTestCase)

However, I you want to create more TestCases it is good idea to add them to a TestSuite. For instance something like this:

import unittest
class MyFirstTestCase(unittest.TestCase):
    # ...

class AnotherTestCase(unittest.TestCase):
    def setUp(self):
        # SetUp code

    def tearDown(self):
        # TearDown code

    def test_another_thing(self):
        # some test code

    def test_yet_another_thing(self):
        # more test code


if __name__ == '__main__':

    def suite():
        suite = unittest.TestSuite()
        suite.addTest(MyFirstTestCase('test_something'))
        suite.addTest(AnotherTestCase('test_another_thing'))
        return suite

    my_suite = suite()
    import rostest
    rostest.rosrun('my_package', 'test_my_first_test_suite', my_suite)

Note that the call to rostest.rosrun uses a unittest.TestSuite as argument rather than a unittest.TestCase.

But it seems that rostest.rosrun is not compatible with unittest.TestSuite, since after runing this code you would get a TypeError like the following:

rostest.rosrun('my_package','test_my_first_test_case', my_suite)
File "/opt/ros/groovy/lib/python2.7/dist-packages/rostest/__init__.py", line 136, in rosrun suite = unittest.TestLoader().loadTestsFromTestCase(test) File "/usr/lib/python2.7/unittest/loader.py", line 50, in loadTestsFromTestCase if issubclass(testCaseClass, suite.TestSuite): TypeError: issubclass() arg 1 must be a class

After reading the documentation and looking for some examples I did not found any way to call a TestSuite from rostest. Is it any way to properly create a TestSuite under rostest?

Some partial solution would be calling the different TestCases in different calls to rostest.rosrun like that:

rostest.rosrun('my_package', 'test_my_first_test_case', MyFirstTestCase)
rostest.rosrun('my_package', 'test_another_test_case', AnotherTestCase)

But, somehow, rostest only outputs the results for the second call to rostest.rosrun unless --text is passed (see this question). This is not desirable since --text is more verbose and increases testing time. Moreover, I believe using a TestSuite would be much more flexible than manully adding calls to rostest.rosrun.

EDIT: I edited the title to make the question clearer.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-05-30 17:34:08 -0500

130s gravatar image

updated 2014-05-30 17:35:44 -0500

My guess is that (someone correct me if I'm wrong) the term suite may be used in rostest not as its specific usage in software testing context (as in testsuite) but as something more general, like composite or group of TestCases. And unittest.TestSuite isn't handled yet in rostest.

Thus it's worth opening an enhancement request on its issue tracker.

(As a workaround I usually put TestCase classes in separate .py files, which isn't that cumbersome if I have only several TestCases.)

edit flag offensive delete link more

Comments

1

Thanks Isaac, I opened an issue 423

Victor Gonzalez-Pacheco gravatar image Victor Gonzalez-Pacheco  ( 2014-06-02 03:59:52 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-01-27 01:47:37 -0500

Seen: 797 times

Last updated: Jun 02 '14