When writing gtests with ROS, why doesn't the FRIEND_TEST macro work? [closed]
For unit testing, I need to write gtests that can access at least some private data. The FRIEND_TEST macro doesn't seem to be working however. In the example here, I have my so-called "targetClass" whose privateMap I wish to access. This has not been compiling for me.
Within targetClassTester, I have this:
TEST_F(tester_base, exp)
{
myMap = myTargetClass.privateMap;
}
Meanwhile, in the header file for targetClass, I have the following in the private section:
FRIEND_TEST(tester_base, exp);
Finally, the following shows what the relevant parts of CMakeLists.txt would look like: (As a special note, targetClass.cpp contains a main() method and is normally created as its own executable. It's only for testing that I created the "targetClassForTesting" library. For unit testing, the main() method in targetClass.cpp is ignored.)
add_library(targetClassForTesting src/targetClass.cpp include/au_uav_ros/targetClass.h)
add_executable(targetClassTester include/myPackage/test/targetClassTester.h src/test/targetClassTester.cpp include/au_uav_ros/targetClass.h)
target_link_libraries(targetClassTester ${catkin_LIBRARIES} ${GTEST_LIBRARIES} targetClassForTesting)
add_rostest(test/targetClassTester.test)
There don't seem to be any other questions on the internet about FRIEND_TEST malfunctioning, making me think the issue is particular to ROS.
Let me know if you need any more information. Thank you.
There's no expected issues with integrating with googletest elements. What is your actual error? Without an actual error it's hard to help you.
Same problem. Actual error: Compilation fails with msg error: ‘void TargetClass::privateMap()’ is private within this context
I'm experiencing this same issue. Did you find a solution?
I've found workaround which satisfied my need.
Then to enable testing in cmake file you can do