Skip to content

Commit

Permalink
Added unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
matteodv99tn committed Nov 21, 2024
1 parent 05ab716 commit f12ec8a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ jobs:
distro: humble

- name: Build the workspace
uses: ichiro-its/ros2-ws-action/[email protected]
uses: ichiro-its/ros2-ws-action/[email protected]

- name: Test the workspace
run: |
source install/setup.bash
colcon test --return-code-on-test-failure
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ find_package(ament_cmake REQUIRED)

set(ROS2_REQUIRED_COMPONENTS
rclcpp
std_msgs
)
foreach(COMPONENT ${ROS2_REQUIRED_COMPONENTS})
find_package(${COMPONENT} REQUIRED)
Expand Down Expand Up @@ -36,4 +37,12 @@ install(
DESTINATION lib/${PROJECT_NAME}
)

if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
ament_add_gtest(
unit_testing
src/unit_tests.cpp
)
endif()

ament_package()
15 changes: 15 additions & 0 deletions src/unit_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <gtest/gtest.h>


int a_complex_function(int x) { return 2*x; }



TEST(cpp_publisher_subscriber, useless_test) {
ASSERT_EQ(a_complex_function(2), 5);
}

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

0 comments on commit f12ec8a

Please sign in to comment.