返回介绍

测试和持续集成 - 综合测试

发布于 2020-07-27 14:09:26 字数 6666 浏览 1014 评论 0 收藏 0

This is about end to end integration testing. Tests are executed automatically (Jenkins CI)

ROS / MAVROS Tests

Prerequisites:

  • JMAVSim Simulation
  • Gazebo
  • ROS and MAVROS

Execute Tests

To run the complete MAVROS test suite:

  1. cd <Firmware_clone>
  2. source integrationtests/setup_gazebo_ros.bash $(pwd)
  3. rostest px4 mavros_posix_tests_iris.launch

Or with GUI to see what’s happening:

  1. rostest px4 mavros_posix_tests_iris.launch gui:=true headless:=false

Write a new MAVROS test (Python)

Note Currently in early stages, more streamlined support for testing (helper classes/methods etc.) to come.

1.) Create a new test script

Test scripts are located in integrationtests/python_src/px4_it/mavros/. See other existing scripts for examples. Also please consult the official ROS documentation on how to use unittest.

Empty test skeleton:

  1. #!/usr/bin/env python
  2. # [... LICENSE ...]
  3. #
  4. # @author Example Author <author@example.com>
  5. #
  6. PKG = 'px4'
  7. import unittest
  8. import rospy
  9. import rosbag
  10. from sensor_msgs.msg import NavSatFix
  11. class MavrosNewTest(unittest.TestCase):
  12. """
  13. Test description
  14. """
  15. def setUp(self):
  16. rospy.init_node('test_node', anonymous=True)
  17. rospy.wait_for_service('mavros/cmd/arming', 30)
  18. rospy.Subscriber("mavros/global_position/global", NavSatFix, self.global_position_callback)
  19. self.rate = rospy.Rate(10) # 10hz
  20. self.has_global_pos = False
  21. def tearDown(self):
  22. pass
  23. #
  24. # General callback functions used in tests
  25. #
  26. def global_position_callback(self, data):
  27. self.has_global_pos = True
  28. def test_method(self):
  29. """Test method description"""
  30. # FIXME: hack to wait for simulation to be ready
  31. while not self.has_global_pos:
  32. self.rate.sleep()
  33. # TODO: execute test
  34. if __name__ == '__main__':
  35. import rostest
  36. rostest.rosrun(PKG, 'mavros_new_test', MavrosNewTest)

2.) Run the new test only

  1. # Start simulation
  2. cd <Firmware_clone>
  3. source integrationtests/setup_gazebo_ros.bash $(pwd)
  4. roslaunch px4 mavros_posix_sitl.launch
  5. # Run test (in a new shell):
  6. cd <Firmware_clone>
  7. source integrationtests/setup_gazebo_ros.bash $(pwd)
  8. rosrun px4 mavros_new_test.py

3.) Add new test node to launch file

In launch/mavros_posix_tests_irisl.launch add new entry in test group:

  1. <group ns="$(arg ns)">
  2. [...]
  3. <test test-name="mavros_new_test" pkg="px4" type="mavros_new_test.py" />
  4. </group>

Run the comlpete test suite as described above.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文