Domotest – A Lua rock to aid testing Domoticz event scripts

Moderator: leecollings

Post Reply
nxsteveo
Posts: 1
Joined: Sunday 09 October 2016 20:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Domotest – A Lua rock to aid testing Domoticz event scripts

Post 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...
User avatar
remb0
Posts: 499
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

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

Post by remb0 »

thanks for sharing!
:!:
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest