Skip to content
This repository has been archived by the owner on Jun 28, 2020. It is now read-only.

Testing Guide

Alec C edited this page Jun 1, 2019 · 4 revisions

Unit Testing Getting Started

Existing packages can be configured for tests by adding the following this guide.

Configuring Build System

To configure the build via. catkin_make append the following cmake code to the end of the package's CMakeLists.txt file.

catkin_add_gtest(${PROJECT_NAME}-test test/test_tests.cpp)
if(TARGET ${PROJECT_NAME}-test)
  ## Other libraries can be appended in subsequent target_link_libraries calls
  ## or in the same call after ${catkin_LIBRARIES}
  target_link_libraries(${PROJECT_NAME}-test ${catkin_LIBRARIES})
endif()

Setting Up Required Files

As seen in the CMakeLists.txt addition, we're referencing a test_test.cpp file in the test directory. The directory test and the file within will need to be created to get catkin to not complain about them not existing. Follow the following for how your new test directory should be structured

polaris/ros/src/
|- ...
└- <package>
   |- ... (other files/directories)
   |- test/            (the new directory for the test file)
   |  └- test_test.cpp (the new test c++ file)
   └- CMakeLists.txt

Basic Test Source Requirements

The following c++ code needs to be placed in the test_tests.cpp file.

#include <ros/ros.h> // (if the tests need ROS)
#include <gtest/gtest.h>

// === BEGIN TEST CASE SECTION ===

// === END   TEST CASE SECTION ===

int main(int argc, char** argv)
{
  testing::InitGoogleTest(&argc, argv);
  ros::init(argc, argv, "ai_test");
  return RUN_ALL_TESTS();
}

Writing Tests

For now please refer to the gtest documentation, this is available here: https://github.com/google/googletest

Clone this wiki locally