RclexTesting (RclexTesting (Experimental) v0.12.11)

Copy Markdown View Source

A Phoenix.LiveViewTest-style testing library for ROS2 applications built with rclex.

Provides a high-level scenario DSL for expressing robot behaviour as executable test specifications without manually managing nodes, publishers, subscriptions, or assertion loops.

Usage

defmodule RobotTest do
  use ExUnit.Case
  use RclexTesting

  scenario "robot starts mission" do
    watch "/robot/state", MyPkg.Msg.RobotState
    publish "/mission/start", MyPkg.Msg.MissionStart.new(id: 42)
    expect "/robot/state", &(&1.state == :running)
  end
end

Options

Every DSL function that creates or uses an rclex entity accepts an optional trailing keyword list. :timeout is consumed by the DSL; every other option is forwarded verbatim to the underlying Rclex call — :qos, :namespace, :introspection, action :options and callbacks, and so on.

watch "/scan", LaserScan, qos: Rclex.QoS.profile_sensor_data()
expect "/scan", &(&1.ranges != []), timeout: 10_000

:namespace identifies the scenario node, not a topic prefix. Set it once with scenario/3 and every DSL call in the block inherits it:

scenario "namespaced robot", namespace: "/robot1" do
  publish "/mission/start", %MissionStart{id: 42}
end

DSL

The scenario DSL is organized into the following modules:

use RclexTesting imports every DSL module, scenario declarations, and RclexTesting.Matchers.