I posted this question to ROS answers page but did not get any help: https://answers.ros.org/question/350204/do-rostest-test-nodes-publish-to-rosout/
Reposting here to see if I can get any help. Feel free to continue the discussion over there or start a new one here.
Some background. I am new to writing unit tests in gtests/rostest. So a lot of this might be just me unable to find that awesome link which will clear everything up. The course on Robot Ignite Academy focuses on python unittests and not gtest CPP. There is one Construct video on Youtube for CPP/gtests but that does not solve my problem, Anyway, here it goes:
My node under test: This node is only subscribing to
/rosout_agg . Think of this as some sort of diagnostics node.
My test scenario: I want to publish several series of messages to
/rosout from my test cases and see how my diagnostics node responds to this. So I was thinking I will just use the log statements such as
ROS_ERROR to publish my test case messages onto
/rosout . I am not directly publishing to this topic. Rather just using the log statements.
rostest file looks like follows:
<?xml version="1.0"?> <launch> <node pkg="diagnostics" type="diagnostics" name="diagnostics_node" output="screen"/> <test test-name="diagnostics_test_node" pkg="diagnostics" type="diagnostics_test_node"/> </launch>
- When I run this file using
rostest, my diagnostics node is not picking up any messages from
/rosout_agg. The subscriber callback in my node under test never gets called.
- Note that, when I run my
diagnostics_test_nodeas just a gtest and my diagnostics node separately, everything is working as expected.
So the question I have is, do the test nodes that
rostest starts automatically start a
rosout as well (The log XML file does not seem to have any mention of starting rosout)? What happens to the messages created by the log statements in the test node in this case? Should I be directly publishing to
/rosout instead of using log statements? Any other ideas on how I should be testing a stream of messages from
Please let me know if I can expand on my question!