Creating automated tests for my SmartApp

I’m creating a non-trivial SmartApp (a few hundred lines of code) and would like to create some automated tests. I’m curious if there’s a recommended way to automate tests and what other people do.

My tests would look something like:

  1. Set temperature A to X
  2. Set temperature B to X
  3. Turn motionDetector C to “active”
  4. Assert(switchD = “on”)

Is this possible or will I need to do everything manually through the simulator?

1 Like

I’ve thought about this before. Some of it you can do easily, some of it you will need to build a virtual device for (setting a motion sensor to active).

For example…

def runTests() {
    testOn()
    testOff()
}

def testOn() {
    switches.each { it->
         it.on()
    }
    runIn(5, testIsOn)
}

def testIsOn() {
    def result = true

    switches.each { it->
        if(it.currentValue("switch") == "on") {
            log.debug "Yes, ${it.displayName} is on!"
        } else {
            log.error "No, ${it.displayName} is not on!"
            result = false
        }
    }

    return result
}
1 Like

Thanks (again) Eric. Let me read more about devices and virtual devices and try this out.

Take a look at my settable temperature sensor. It looks like a temperature sensor to SmartThings, but it has the a method that I added to manually set the temperature.

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.