Should core ROS classes implement interfaces for easier mocking?

asked 2021-01-12 03:53:26 -0600

Rufus gravatar image

Mocking is very useful when writing unit tests for code that needs to interface with external systems (e.g. ROS).

Most of the time, onle only needs to test that the external API (e.g. pub.publish()) is called. Whether that API actually does anything (e.g. publish a message) is irrelevant. In these cases, mocking allows one to ascertain that the correct APIs are called. Specifically for ROS, mocking also allows unit tests to avoid the non-determinsitic network latancy.

Having said that, in order for a class to be easily mocked, they need to implement an interface. However, many important ROS classes, e.g. Publisher, Subscriber, SimpleActionServer, etc. do not implement interfaces.

I was wondering if there has been any discussion regarding this.

edit retag flag offensive close merge delete

Comments

For reference, #q366405 is a related question by the OP

mgruhler gravatar image mgruhler  ( 2021-01-12 04:52:55 -0600 )edit

Sorry I forgot I asked this question before..

Rufus gravatar image Rufus  ( 2021-01-12 08:14:24 -0600 )edit

no worries, @Rufus, I actually did not consider this to be a duplicate, as this question has a broader scope, but as it is directly related to other one, I guess that answering this one would also answer the other :-)

mgruhler gravatar image mgruhler  ( 2021-01-12 08:28:49 -0600 )edit