nodelet_core icon indicating copy to clipboard operation
nodelet_core copied to clipboard

Unit Testing Nodelets

Open progtologist opened this issue 10 years ago • 2 comments

While using nodelets, I discovered that the API does not provide a method for returning a nodelet object from the nodelet loader. Although such a method is not the proposed way to use nodelets, it would be very useful for unit testing nodelets with google tests.

Right now, the only way to do this is to use the

nodelet::Loader::Loader(const boost::function< boost::shared_ptr< Nodelet >(const std::string &lookup_name)> &  create_instance)

method to instantiate the object, and to share that pointer with the unit tests. However it would be more elegant to be able to get the object (pointer) using a loader method.

progtologist avatar Dec 31 '15 13:12 progtologist

do you by any chance still have an example of this?

daniel-dsouza avatar Mar 22 '21 21:03 daniel-dsouza

Unfortunately I don't have access to that code anymore. If I remember correctly though, you must create a function that creates nodelets and create a loader providing that function. In your function you can have a std::map or even an std::vector that, while instantiating the nodelet, also adds it to that structure. From your app, you use that new loader to instantiate the nodelet, and you can access that structure to get your instance at any time.

progtologist avatar Mar 23 '21 12:03 progtologist