Page 1 of 1

Domotest – A Lua rock to aid testing Domoticz event scripts

Posted: Sunday 09 October 2016 20:18
by nxsteveo
I made a little Lua library/script to help with unit testing Domoticz event scripts. It hides a lot of the boilerplate required to get standard Domoticz-compatible Lua scripts loaded into a test environment (such as Busted).

Useful if you don't have actual devices and want to get a script up and running, or if you want/need the security of having your event scripts covered by tests.

Code: Select all

require 'domotest'
require 'busted.runner'()
 
describe('Bathroom motion sensor', function()
 
  describe('detects motion at night', function()
 
    it('turns on the light', function()
      commandArray = domotest('script_device_bathroommotion.lua', {
        devicechanged = { ['Bathroom Motion'] = 'On' },
        timeofday = { ['Nighttime'] = true }
      })
 
      assert.are.same({
        ['Bathroom Lights'] = 'On'
      }, commandArray)
    end)
 
  end)
 
end)
Installation is simple with luarocks:

Code: Select all

luarocks install domotest
:D

There's a bit more info on the blog post here: http://stevewilford.co.uk/2016/10/domotest-launch/

And even more info, and examples, in the git repo: https://github.com/NxSoftware/domotest

Hope this is of use to someone...

Re: Domotest – A Lua rock to aid testing Domoticz event scripts

Posted: Sunday 09 October 2016 21:29
by remb0
thanks for sharing!
:!: