Skip to content

Unit Testing Drivers

Stephen von Takach edited this page Jun 15, 2017 · 8 revisions

Tests describe the behaviour of a driver and can be used to help with development. They are also useful in describing the intended usage of a driver.

See for example usage

Checking values

We use rspec-expectations for verifying status variables and command results returned expected values.

Running Tests

There is a rake task where you can specify the file containing the driver spec. Drivers themselves are resolved and loaded internally, as they would be in a running system.

rake module:test['../aca-device-modules/modules/extron/switcher/dxp_spec.rb']

Helper Functions

Helper Arguments Description
transmit / responds string / hex string / byte array emulates a device sending data to the module
exec function_name, *args calls the function requested on the module with the arguments provided
should_send string / hex string / byte array this is the data the driver is expected to send to the device
result provides access to the result of the last executed request
status provides access to the current status of the driver
temporary_disconnect emulates a connection drop followed by re-establishment
device_offline emulates a connection drop where communications have failed to be re-established
device_online emulates connection re-establishment. Should only be called after a device_offline
wait_tick times = 1 resumes the test after the specified number of ticks through the event loop
wait milliseconds resumes the test after waiting the specified amount of time