Skip to content

Commit

Permalink
Merge pull request #7 from Scarabrine/master
Browse files Browse the repository at this point in the history
Add gtest for library and rostest for nodes
  • Loading branch information
yuxuan83 committed Nov 5, 2018
2 parents 9b0613c + fe30ee0 commit f78ef03
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ros/src/models/chrono/ros_chrono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,16 @@ target_link_libraries(velocity_controller

## Add folders to be run by python nosetests
# catkin_add_nosetests(test)

#####################
# g Tests and rostest
#####################
# New added for rostest
if(CATKIN_ENABLE_TESTING)
message("\n\nGoing to build the ros_chrono tests!\n\n")
find_package(rostest REQUIRED)
# You can add arbitrary new test files in the end of add_rostest_gtest
add_rostest(launch/steering.launch) #perhaps

endif()
# End rostest
3 changes: 3 additions & 0 deletions ros/src/models/chrono/ros_chrono/launch/steering.launch
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
<rosparam command="load" file="$(arg chrono_params_path)"/>

<node name="Reference" pkg="traj_gen_chrono" type="traj_gen_chrono"/>
<test test-name="Reference_test" pkg="traj_gen_chrono" type="traj_gen_chrono"/>

<node name="Chronode" pkg="ros_chrono" type="steering_controller" cwd="node" />
<test test-name="Chronode_test" pkg="ros_chrono" type="steering_controller" />
</launch>
5 changes: 5 additions & 0 deletions ros/src/models/chrono/ros_chrono/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<!-- <doc_depend>doxygen</doc_depend> -->
<buildtool_depend>catkin</buildtool_depend>

<!-- New added part for rostest, start -->
<depend>rostest</depend>
<depend>genmsg</depend>
<!-- New added part for rostest, end -->

<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
Expand Down
16 changes: 16 additions & 0 deletions ros/src/system/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@ add_executable(system_shutdown src/system_shutdown.cpp)
target_link_libraries(system_shutdown ${catkin_LIBRARIES})

add_dependencies(system_shutdown ${catkin_EXPORTED_TARGETS})

#####################
# g Tests and rostest
#####################
# New added for rostest
if(CATKIN_ENABLE_TESTING)
message("\n\nGoing to build the tests!\n\n")
find_package(rostest REQUIRED)
find_package(gtest)
# You can add arbitrary new test files in the end of add_rostest_gtest
add_rostest_gtest(test_mynode test/gtest_launch.launch src/test/mytest.cpp)
add_rostest(launch/demoA.launch) #perhaps

target_link_libraries(test_mynode ${catkin_LIBRARIES} ${GTEST_LIBRARIES})
endif()
# End rostest and gtest
3 changes: 3 additions & 0 deletions ros/src/system/launch/demoA.launch
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@
<node name="system_shutdown" pkg="system" type="system_shutdown" output="screen" required="true">
<rosparam file="$(arg system_params_path)" command="load"/>
</node>
<test test-name="system_shutdown" pkg="system" type="system_shutdown" />

<!-- initialize system -->
<node name="bootstrap" pkg="system" type="bootstrap.jl" output="screen"/>
<test test-name="bootstrap" pkg="system" type="bootstrap.jl" />

<!-- unpause Gazebo -->
<node name="unpause_gazebo" pkg="vehicle_description" type="unpause.jl" output="screen"/>
<test test-name="unpause_gazebo" pkg="vehicle_description" type="unpause.jl" />

</launch>
6 changes: 6 additions & 0 deletions ros/src/system/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<depend>roscpp</depend>
<depend>rospy</depend>

<!-- New added part for rostest, start -->
<depend>rostest</depend>
<depend>genmsg</depend>
<depend>std_msgs</depend>
<!-- New added part for rostest, end -->

<exec_depend>nloptcontrol_planner</exec_depend>
<exec_depend>vehicle_description</exec_depend>
<exec_depend>obstacle_detector</exec_depend>
Expand Down
18 changes: 18 additions & 0 deletions ros/src/system/src/test/mytest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "ros/ros.h"
#include <gtest/gtest.h>


TEST(MAVsTester, basicTest){

int a = 1;
int b = 2;
int c = a+b;
std::cout << "\n\n\nThis comes form inside of one test case\n\n\n";

EXPECT_EQ(c, 3);
}

int main(int argc, char** argv){
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
3 changes: 3 additions & 0 deletions ros/src/system/test/demo_test.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<launch>
<test test-name="demoA" pkg="system" type="testA.py" />
</launch>
3 changes: 3 additions & 0 deletions ros/src/system/test/gtest_launch.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<launch>
<test test-name="test_mynode" pkg="system" type="test_mynode" />
</launch>

0 comments on commit f78ef03

Please sign in to comment.