How to test the private functions inside a ROS node?
Hello,
I have a package that contains a single executable which relies on the messages implemented in another three packages and I would like to test this executable. So far I think I understand how to test the node itself with the help of rostest, but first I need to have tests for a handful of functions I have inside the node. These functions are supposed to be private (delcared as static
inside the node's source file), so they are not part of any API I could expose to the test driver.
How could I go about it? The tests would be extremely simple, the functions just take a ROS message object as input and provide a plain C structure with the contents of the message, so the test would simply input a ROS message and check that the output parameters correspond to those in the input message.
Do you have any ideas how to approach this when it would be anything else (ie: not a ROS node)?
No. I checked the resources available in the ROS Wiki and these examples: https://answers.ros.org/question/1817... , but they all seem to either assume a library with a public interface or a running node.
I wasn't asking about how to do it "within ROS" :)
Sorry, I was also talking about the gtest-only resources included in the wiki (the Level1 testing with no rostest). These haven't been very helpful so far, to be honest.
No need to apologise. What I wanted to get across is that ROS is not special here, and afaict does not change anything that you couldn't use when testing functions/methods local to a compilation unit without involving ROS.
See this SO post and this thread on reddit for some common approaches. this is nice.
Can you get to your private functions via callbacks from services or subscribers? If so, then rostest provides a way to have a test node that can publish messages or call servers in a way that will invoke functions triggered by your callbacks. If that is useful I can put links.
Only one of the functions is passed as a callback for the reception of a message in a given topic, the rest are called periodically by main(), so I don't think I can benefit from it. Still, could you please post the links? Sounds like an interesting piece of information.