Interfaces of ROS classes for mocking and dependency injection
I am trying to write unit tests for my class that interacts with various ROS ServiceClient
and SimpleActionClient
. Since I'm fairly confident in ROS and don't want to handle the indeterminacy of network latency in my unit tests, I plan to have my unit tests cover the interface between my class and ROS only.
Hence, I would need to mock the ServiceClient
and SimpleActionClient
. In order to mock, the things I am mocking needs to implement an interface (lest I be forced to use this uglier method.
My question is, does the ServiceClient
and SimpleActionClient
implement any interface that I can mock? If not, is there any best practices for mocking common ROS classes?
My current implementation is to use dependency injection to allow me to separate and swap out the concrete ROS stuff with (hopefully) mocked ROS stuff
PayloadController::PayloadController(
ros::ServiceClient& service_client,
actionlib::SimpleActionClient<...>& action_client)
PS:: To my blessing, tf2_ros::Buffer
implements the BufferInterface
which allowed me to mock and unit test code that used TF2 easily