You will need to depend on the rosunit package in order to setup your Python path correctly. You can have ROS automatically run these tests when you type make test by adding the following to your CMakeLists.txt: Running tests as part of 'make test'/CMakeLists.txt unitrun( package_name, test_name, test_case_class, sysargs= None, coverage_packages= None) 2 You can also write normal Python unit tests with ROS based on the Python unittest framework.ġ rosunit. Please see the rostest documentation on how to integrate your node into an integration test. The rostest tool is based on roslaunch, so this is similar to writing a roslaunch file for your test. You will need to run your node in a rostest file. You will need to depend on the rostest package in order to setup your Python path correctly. rostest also examines sys.argv for command-line arguments such as -text and -gtest_output. $ROS_ROOT/test/test_results/''package_name''/TEST-''test_name''.xml). Package_name and test_name control where your XML test results are placed (i.e. The rostest.rosrun method assumes that your test is a rospy node and will perform extra operations to try and make sure that your node properly runs and is shut down. List of packages that should be included in coverage report.This name will be used in the filename of the test results as well as in the XML results reporting.Ĭoverage_packages= Test results are aggregated by package name. Name of ROS package to record these results as.rosrun( package_name, test_name, test_case_class, sysargs= None, coverage_packages= None) 2 You just have to wrap your code using the Python unittest framework.Ī bare-bones test results looks as follows:ġ rostest. Writing a unit test that acts as a ROS node is fairly simple in Python. Node-level tests will incur additional ROS resources to test whereas code-level tests are more lightweight. The syntax for running these tests is different, so it's important that you properly distinguish between the two. For these tests, it is assumed that your test script is itself a node.Ĭode-Level Unit Tests: in general, these tests make direct calls into your code i.e. ROS-Node-Level Integration Tests: in general, these test against the external topic/service API of a Node. There are two style of tests that are supported: In other words, Python unittest-based tests are compatible with ROS as long as you add an extra wrapper that creates the necessary XML results output. Python unit tests use the built-in unittest module with a small wrapper to enable XML output of the test results. Running tests as part of 'make test'/CMakeLists.txt.
0 Comments
Leave a Reply. |