Skip to content

Commit 50bdc8b

Browse files
committed
add Integration test node
1 parent f4f1129 commit 50bdc8b

File tree

5 files changed

+123
-1
lines changed

5 files changed

+123
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(integration_test)
3+
4+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5+
add_compile_options(-Wall -Wextra -Wpedantic)
6+
endif()
7+
8+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../external_pkgs/Catch2 ${CMAKE_CURRENT_BINARY_DIR}/external_pkgs/Catch2) # Include Catch2 for unit tests
9+
10+
include_directories(include/)
11+
12+
13+
# find dependencies
14+
find_package(ament_cmake REQUIRED)
15+
find_package(rclcpp REQUIRED)
16+
find_package(rover_utils REQUIRED)
17+
find_package(sensor_msgs REQUIRED)
18+
find_package(example_interfaces REQUIRED)
19+
20+
21+
add_executable(integration_tester src/assert_node.cpp)
22+
ament_target_dependencies(integration_tester rclcpp sensor_msgs rover_utils example_interfaces)
23+
24+
target_link_libraries(integration_tester
25+
Catch2::Catch2)
26+
27+
install(
28+
TARGETS
29+
integration_tester
30+
DESTINATION lib/${PROJECT_NAME}
31+
)
32+
33+
ament_package()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
How to integration tests?
2+
3+
scopeout:
4+
1. can catch2 be used? or should not bother?

src/integration_test/package.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>integration_test</name>
5+
<version>0.0.0</version>
6+
<description>TODO: Package description</description>
7+
<maintainer email="[email protected]">rowan</maintainer>
8+
<license>TODO: License declaration</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<depend>rclcpp</depend>
13+
<depend>rover_utils</depend>
14+
<depend>sensor_msgs</depend>
15+
16+
<test_depend>ament_lint_auto</test_depend>
17+
<test_depend>ament_lint_common</test_depend>
18+
19+
<export>
20+
<build_type>ament_cmake</build_type>
21+
</export>
22+
</package>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// name?
2+
3+
#include <rclcpp/rclcpp.hpp>
4+
#include <sensor_msgs/msg/joy.hpp>
5+
#include <example_interfaces/msg/int32.hpp>
6+
#include <catch2/catch_all.hpp>
7+
8+
// Class definition
9+
class IntegrationTestNode : public rclcpp::Node {
10+
public:
11+
IntegrationTestNode(); // Constructor is defined in .cpp.
12+
13+
private:
14+
// SUBS AND PUBS
15+
rclcpp::Publisher<sensor_msgs::msg::Joy>::SharedPtr joy_publisher;
16+
17+
rclcpp::Publisher<example_interfaces::msg::Int32>::SharedPtr checker_pub;
18+
rclcpp::Subscription<example_interfaces::msg::Int32>::SharedPtr checker_sub;
19+
20+
// Callbacks
21+
void test_callback(example_interfaces::msg::Int32 msg);
22+
23+
};
24+
25+
// Constructor
26+
IntegrationTestNode::IntegrationTestNode() : Node("integration_test_node")
27+
{ // We create a class using rclcpp::Node as a base class. You can still use another base class if you need, albeit sometimes with difficulties in passing args..
28+
29+
// Quality of service example
30+
auto qos = rclcpp::QoS(rclcpp::KeepLast(1)).transient_local();
31+
32+
joy_publisher = this->create_publisher<sensor_msgs::msg::Joy>(
33+
"/joy", qos);
34+
35+
checker_pub = this->create_publisher<example_interfaces::msg::Int32>(
36+
"/integration/test_int", qos);
37+
38+
checker_sub = this->create_subscription<example_interfaces::msg::Int32>(
39+
"/integration/test_int", qos, std::bind(&IntegrationTestNode::test_callback, this, std::placeholders::_1));
40+
41+
}
42+
43+
// Main function (entry point of node)
44+
int main(int argc, char *argv[])
45+
{
46+
// Init ros2 with args.
47+
rclcpp::init(argc, argv);
48+
49+
// Instatiate your node
50+
auto node = std::make_shared<IntegrationTestNode>();
51+
// Spin it! (this is what runs pubs and subs. This is a blocking function)
52+
rclcpp::spin(node);
53+
// There is also rclcpp::spinSome(node) if you need more control over when the node spins / need to not block while spinning.
54+
55+
// Code only reaches here if we crash or shutdown the node
56+
rclcpp::shutdown();
57+
return 0;
58+
}
59+
60+
void IntegrationTestNode::test_callback(example_interfaces::msg::Int32 msg)
61+
{
62+
63+
}

src/rover_samples/rv_sample_package/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.10)
1+
cmake_minimum_required(VERSION 3.15)
22
project(rv_sample_package)
33

44
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")

0 commit comments

Comments
 (0)