- 综合测试
- ROS / MAVROS测试
- 执行测试
- 编写新的MAVROS测试 (Python)
- 1.) 创建新的测试脚本
- 2.) 只运行新的测试
- 3.) 添加新的测试结点到launch文件
- ROS / MAVROS测试
综合测试
官网英文原文地址:http://dev.px4.io/tutorial-integration-testing.html
这是综合测试,测试会自动执行(Jenkins CI)。
ROS / MAVROS测试
前提:
- SITL仿真
- Gazebo
- ROS and MAVROS
执行测试
运行完整的MAVROS测试套件:
cd <Firmware_clone>source integrationtests/setup_gazebo_ros.bash $(pwd)rostest px4 mavros_posix_tests_iris.launch
或者使用GUI查看:
rostest px4 mavros_posix_tests_iris.launch gui:=true headless:=false
编写新的MAVROS测试 (Python)
目前处于早期阶段,采用了很多简化测试(helper classes/methods etc.)。
1.) 创建新的测试脚本
测试脚本位于integrationtests/python_src/px4_it/mavros/,可以参考这些脚本文件。或者查阅ROS官方文档学习如何使用unittest。
空的测试框架:
#!/usr/bin/env python# [... LICENSE ...]## @author Example Author <author@example.com>#PKG = 'px4'import unittestimport rospyimport rosbagfrom sensor_msgs.msg import NavSatFixclass MavrosNewTest(unittest.TestCase):"""Test description"""def setUp(self):rospy.init_node('test_node', anonymous=True)rospy.wait_for_service('mavros/cmd/arming', 30)rospy.Subscriber("mavros/global_position/global", NavSatFix, self.global_position_callback)self.rate = rospy.Rate(10) # 10hzself.has_global_pos = Falsedef tearDown(self):pass## General callback functions used in tests#def global_position_callback(self, data):self.has_global_pos = Truedef test_method(self):"""Test method description"""# FIXME: hack to wait for simulation to be readywhile not self.has_global_pos:self.rate.sleep()# TODO: execute testif __name__ == '__main__':import rostestrostest.rosrun(PKG, 'mavros_new_test', MavrosNewTest)
2.) 只运行新的测试
# Start simulationcd <Firmware_clone>source integrationtests/setup_gazebo_ros.bash $(pwd)roslaunch px4 mavros_posix_sitl.launch# Run test (in a new shell):cd <Firmware_clone>source integrationtests/setup_gazebo_ros.bash $(pwd)rosrun px4 mavros_new_test.py
3.) 添加新的测试结点到launch文件
在launch/mavros_posix_tests_irisl.launch中的测试组中添加新的条目:
<group ns="$(arg ns)">[...]<test test-name="mavros_new_test" pkg="px4" type="mavros_new_test.py" /></group>
按照前文所述方法运行完整测试套件。
