ROS-gtest使用
ROS-gtest使用
1.官网参考
https://github.com/google/googletest
2.在包名子目录创建 test/test_*.cpp,如
内容如下:
#include <tf/transform_listener.h>
#include "aoa_follow.h"
int val2 =2;
TEST(ycy, mytest)
{
EXPECT_TRUE(true);
ASSERT_EQ(2,val2);
}
TEST(zy, zytest)
{
EXPECT_TRUE(true);
}
int main(int argc,char **argv)
{
testing::InitGoogleTest(&argc,argv);
ros::init(argc,argv,"tester");
ros::NodeHandle nh;
return RUN_ALL_TESTS();
}
3.修改原有的CMakeLists.txt后面添加,如下
#############
## Testing ##
#############
if(CATKIN_ENABLE_TESTING)
find_package(rostest REQUIRED)
add_rostest_gtest(aoa_follow_test test/alaunch.launch test/test_aoa_follow.cpp)
target_link_libraries(aoa_follow_test ${catkin_LIBRARIES} ${GTEST_LIBRARIES})
endif()
4.package.xml文件添加
<build_depend>gtrostestest</build_depend>
<build_depend>gtest</build_depend>
<build_export_depend>rostest</build_export_depend>
<build_export_depend>gtest</build_export_depend>
<exec_depend>rostest</exec_depend>
<exec_depend>gtest</exec_depend>
5.运行测试
(1)自动运行全部测试
在build文件夹下运行命令make run_tests,完成二进制测试程序生成,同时会自动调用test目录下的所欲.test文件。
测试通过,则类似如下
(2)运行单个测试
catkin_make run_tests<TAB><TAB>
如测试不通过,则错误类似如下
(3)测试结果总结
catkin_test_results build/test_results
cat