MOCK 测试编写

比较菜,cartographer编译一定要加上Mock,所以自己加的一些接口也要写mock测试函数。

1- 比如我在pose_graph_interface加了接口如下

   virtual bool IsTrajectoryExist(int trajectory_id) const = 0;

则我要在mock_pose_graph.h上添加测试函数如下,因为我的接口函数添加了const所以这里要用MOCK_CONST_METHOD1

  MOCK_CONST_METHOD1(IsTrajectoryExist, bool(int));

2- 同样,比如我在map_builder_interface.h中添加了接口

  virtual void SetTrajectoryIdWithTpye(std::string type, int id) = 0;

我需要在map_builder_interface.h中添加测试函数如下

   MOCK_METHOD2(SetTrajectoryIdWithTpye, void(std::string, int));

好了后续有新的体会再来更新。

猜你喜欢

转载自blog.csdn.net/windxf/article/details/110517649