-
Notifications
You must be signed in to change notification settings - Fork 13
Setting Repositories for Unit Tests
Shlok Agarwal edited this page Jan 27, 2018
·
2 revisions
Unit tests are important to ensure continued functionality of code and test individual blocks of code.
Step 1: Install gtests
sudo apt-get install libgtest-dev
cd /usr/src/gtest
sudo cmake CMakeLists.txt
sudo make
#copy or symlink libgtest.a and ligtest_main.a to /usr/lib folder
sudo cp *.a /usr/lib
Step 2: Adding unit tests
Create a test
folder in the project directory if it does not exist.
Create a file-name-test.cpp
file in the test
folder. file-name
should be the name of the file/class for which you want to write unit test.
Find examples on how to write unit tests.
Step 3: Configure CMakeLists.txt Add these to the existing CMake
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
# in this example, test_pelvis_height is the name of the node and pelvis_control_interface_test is the name of the file.
catkin_add_gtest(test_pelvis_height test/pelvis_control_interface_test.cpp)
target_link_libraries(test_pelvis_height ${catkin_LIBRARIES})
Step 4: Configure package.xml
<build_depend>gtest</build_depend>
<run_depend>gtest</run_depend>