An ExUnit case template for integration tests against the UFACTORY firmware simulator (or a physical arm).
Handles the boilerplate that firmware integration tests need:
- Tags every test
:simulator(exclude it by default in yourtest_helper.exs:ExUnit.start(exclude: [:simulator])) and applies a generous per-test timeout — firmware round-trips are slow compared to unit tests. - Gates the whole module on
BB.Ufactory.Simulator.wait_until_ready/1insetup_all, so tests never run against a firmware that is still booting (the simulator accepts TCP several seconds before its services respond — every cold start hits this window). - Imports
BB.Ufactory.Simulatorand aliasesBB.Ufactory.Protocol/BB.Ufactory.Report. - Provides
sim_model/0andsim_joints/0, reading theSIM_MODELenvironment variable so one suite can run against every arm model (matchingmix bb_ufactory.sim start <model>).
Usage
# test/my_robot/simulator_test.exs
defmodule MyRobot.SimulatorTest do
use BB.Ufactory.SimulatorCase
test "arm reports joint state" do
{:ok, report} = current_state()
assert length(Enum.take(report.angles, sim_joints())) == sim_joints()
end
test "my pick pose is reachable" do
{:ok, cmd} = connect_command()
prepare_arm(cmd)
assert {:ok, true} = reachable?(cmd, {300.0, 0.0, 200.0, 3.14, 0.0, 0.0})
end
endRun against a started simulator (see mix bb_ufactory.sim):
mix bb_ufactory.sim start lite6
SIM_MODEL=lite6 mix test --include simulatorOptions
:readiness_timeout— milliseconds to wait for firmware readiness insetup_allbefore failing the module (default 60000):use BB.Ufactory.SimulatorCase, readiness_timeout: 120_000
Tests run against one shared firmware instance, so suites using this
template are implicitly async: false.
Summary
Functions
The joint count of the model under test — see sim_model/0.
The arm model under test, from the SIM_MODEL environment variable
(default :xarm6).
Functions
@spec sim_joints() :: pos_integer()
The joint count of the model under test — see sim_model/0.
@spec sim_model() :: atom()
The arm model under test, from the SIM_MODEL environment variable
(default :xarm6).
Matches the model names accepted by mix bb_ufactory.sim start and
BB.Ufactory.Model.