Testing

The MAVSDK C++ library has both unit and integration tests, written using the Google C++ Test Framework (gtest). The unit tests are run every time new code is committed to the library, and must pass before the code can be merged.

This topic shows how to run the existing tests.

For information on writing tests see: Writing Plugins > Test Code.

Running Unit Tests

To run all unit tests:

./build/default/src/unit_tests_runner

Running Integration Tests

Tests can be run against the simulator (either manually starting PX4 SITL or letting the tests start it automatically) or against a real vehicle.

To run SITL you will need to install the Gazebo simulator. This is included as part of the standard PX4 installation for macOS and Linux. It does not run on Windows.

Autostart PX4 SITL

Make sure that the PX4 Gazebo simulation is built and works:

cd path/to/Firmware/
make px4_sitl gazebo

Then press Ctrl+C to stop the simulation and run the integration tests:

cd path/to/MAVSDK/
AUTOSTART_SITL=1 ./build/debug/src/integration_tests/integration_tests_runner

To run the tests without the 3D viewer (gzclient), use:

AUTOSTART_SITL=1 HEADLESS=1 ./build/debug/src/integration_tests/integration_tests_runner

Run PX4 SITL Manually

Build and run the PX4 simulation manually:

cd path/to/Firmware/
make px4_sitl gazebo

Then run the tests as shown:

cd path/to/MAVSDK/
./build/debug/src/integration_tests/integration_tests_runner

The tests are designed to run in simulation, and may not be safe if run on a real vehicle.

Gtest Tricks

To list all integration tests:

./build/default/src/integration_tests/integration_tests_runner --gtest_list_tests

To run a single integration test:

./build/default/src/integration_tests/integration_tests_runner --gtest_filter="SitlTest.TelemetryAsync"

To run all telemetry tests:

./build/default/src/integration_tests/integration_tests_runner --gtest_filter="SitlTest.Telemetry*"
© MAVSDK Development Team 2017-2023. License: CC BY 4.0            Updated: 2023-12-27 03:58:12

results matching ""

    No results matching ""