Skip to content


This topic explains how to run (and extend) PX4's ROS-based integration tests.

MAVSDK Integration Testing is preferred when writing new tests. Use the ROS-based integration test framework for use cases that require ROS (e.g. object avoidance).

All PX4 integraton tests are executed automatically by our Continuous Integration system.


Execute Tests

To run the MAVROS tests:

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

test_target is a makefile targets from the set: tests_mission, tests_mission_coverage, tests_offboard and tests_avoidance.

Test can also be executed directly by running the test scripts, located under test/:

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

launch/mavros_posix_tests_irisl.launch 中添加测试组中的新条目:

./test/ mavros_posix_tests_offboard_posctl.test


# 开始仿真
cd <Firmware_clone>
source integrationtests/setup_gazebo_ros.bash $(pwd)
roslaunch px4 mavros_posix_sitl.launch

# 运行测试(在新的 shell 中):
cd <Firmware_clone>
source integrationtests/setup_gazebo_ros.bash $(pwd)
rosrun px4

The .test files launch the corresponding Python tests defined in integrationtests/python_src/px4_it/mavros/

Write a New MAVROS Test (Python)

This section explains how to write a new python test using ROS 1/MAVROS, test it, and add it to the PX4 test suite.

We recommend you review the existing tests as examples/inspiration (integrationtests/python_src/px4_it/mavros/). The official ROS documentation also contains information on how to use unittest (on which this test suite is based).

To write a new test:

  1. Create a new test script by copying the empty test skeleton below:

    #!/usr/bin/env python
    # [... LICENSE ...]
    # @author Example Author <>
    PKG = 'px4'
    import unittest
    import rospy
    import rosbag
    from sensor_msgs.msg import NavSatFix
    class 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) # 10hz
         self.has_global_pos = False
     def tearDown(self):
     # General callback functions used in tests
     def global_position_callback(self, data):
         self.has_global_pos = True
     def test_method(self):
         """Test method description"""
         # FIXME: hack to wait for simulation to be ready
         while not self.has_global_pos:
         # TODO: execute test
    if __name__ == '__main__':
     import rostest
     rostest.rosrun(PKG, 'mavros_new_test', MavrosNewTest)
  2. Run the new test only

    • Start the simulator:

      cd <PX4-Autopilot_clone>
      source Tools/simulation/gazebo/setup_gazebo.bash
      roslaunch launch/mavros_posix_sitl.launch
    • Run test (in a new shell):

      cd <PX4-Autopilot_clone>
      source Tools/simulation/gazebo/setup_gazebo.bash
      rosrun px4
  3. Add new test node to a launch file

    • In test/ create a new <test_name>.test ROS launch file.
    • Call the test file using one of the base scripts or
  4. (Optional) Create a new target in the Makefile

    • Open the Makefile
    • Search the Testing section
    • Add a new target name and call the test

    For example:

    tests_<new_test_target_name>: rostest
     @"$(SRC_DIR)"/test/ mavros_posix_tests_<new_test>.test

Run the tests as described above.