!REDIRECT “https://docs.px4.io/master/ko/test_and_ci/integration_testing.html

통합 시험

종단간 통합 시험을 다룹니다. 시험은 자동으로 실행합니다(Jenkins CI)

ROS / MAVROS 테스트

선행조건:

실행 시험

MAVROS 테스트 기반에서 완전한 시험을 실행하려면:

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

또는 GUI에서 어떤 일어나는지 보려면:

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

새 MAVROS 시험 작성 (파이썬)

Note 가장 최신의 스테이지에서는, 시험에 대해 좀 더 간소화한 시원을 앞으로 (헬퍼 클래스/메서드 등) 지원할 예정입니다.

1.) 새 시험 스크립트 작성

시험 스크립트는 integrationtests/python_src/px4_it/mavros/에 있습니다. 다른 예제는 기존 스크립트를 살펴보십시오. unittest 활용법은 공식 ROS 문서를 참고하십시오.

빈 시험 양식은 다음과 같습니다:

  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.) 새 시험만 실행

  1. # Start simulation
  2. cd <PX4-Autopilot_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 <PX4-Autopilot_clone>
  7. source integrationtests/setup_gazebo_ros.bash $(pwd)
  8. rosrun px4 mavros_new_test.py

3.) 파일을 실행할 새 시험 노드 추가

launch/mavros_posix_tests_irisl.launch의 시험 그룹에 새 항목을 추가하십시오:

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

위에서 보여드린 바와 같이 완전한 시험 모음을 실행하십시오.