About unit testing in ROS2 - DI, wrappers and code structure.
Hi all,
Some time ago I used to be responsible of the testing framework of some software products outside of ROS. It's been some time that I am working in ROS now (lately in ROS2) and there are aspects on the testing design of ROS2 that I still don't understand. Specifically, I am talking about unit testing and the fact that many ROS2 functionalities are designed to use rclcpp:Node in an inheritance mode.
As far as I'm concerned in unit testing, you want to test (ideally one) aspect of you own code. This is why many libraries are using Dependency Injection instead of inheritance, to help developers test only their code. Hence, when you want to test, instead of the main library, you inject a mock and you can test your function without the need to call the library.
However, I see that the main code of ros2 and also the tests included use rclcpp:Node directly (without using mocks) and test multiple things (actually it seems that tests are most of the times integration ones and not unit ones). For example
https://github.com/ros2/rclcpp/blob/b...
Also, I tend to find the tests very long and difficult to follow, so I am a bit lost here. I assume I am not understanding something of the idea behind the testing architecture of ROS2. Why so inheritance based? Why testing so many things in a single function?
I have searched for a "testing guideline" or something like that but I am unable to find it. Can anybody enlighten this?
Many thanks