HelloThisIsFlo / Appdaemon-Test-Framework

Clean, human-readable tests for Appdaemon
https://hellothisisflo.github.io/Appdaemon-Test-Framework/
MIT License
45 stars 19 forks source link

Feature Request: Trigger tests using "events" #69

Open CalamarBicefalo opened 2 years ago

CalamarBicefalo commented 2 years ago

This is a great little utility I'm using very much.

However, for the sake of having more expressive tests, it would be great to have a when helper that has the ability to trigger one of the HA "events" as opposed to having to invoke the callback directly.

E.g. a test like this:

def test_entering_the_kitchen(given_that, kitchen_activity, assert_that):
    given_that.state_of(devices.KITCHEN_MOTION).is_set_to(states.OFF)

    when.state_of(devices.KITCHEN_MOTION).changes_to(states.ON)

    assert_that(services.HELPER_SELECT_SET).was.set_to_activity(helpers.KITCHEN_ACTIVITY, activities.PRESENT)

as opposed to a test like this:

def test_entering_the_kitchen(given_that, kitchen_activity, assert_that):
    given_that.state_of(devices.KITCHEN_MOTION).is_set_to(states.ON)

    kitchen_activity.kitchen_activity_controller(None, None, None, None, None)

    assert_that(services.HELPER_SELECT_SET).was.set_to_activity(helpers.KITCHEN_ACTIVITY, activities.PRESENT)

If I want to create abstractions or unit tests I wouldn't really be using this lib, and I think this lib is actually great for testing the HA boundary, at which point accessing implementation details of an app-daemon class seems like a breach of boundaries.

As an added benefits, it renders the callback tests documented in the "bonus" area redundant, and those too are a bit brittle, as they rely on the thing being called, and the exact parameters set on them.

HelloThisIsFlo commented 1 year ago

Hey 👋

For now, you can consider this project unmaintained, unfortunately.

I haven't had time to maintain this repo in the last few years, in good parts because I moved home and I haven't had a HomeAssistant setup for a very long time. So I'm a bit disconnected with the latest updates, and it's a huge overhead to start everything again, get context and understand how to fix issues on this project

However, I've finally taken the task to set up my server at home again, so I'll probably use this project for my own use again soon.

This means I may bring this project up-to-date in the next few months. No guarantees, obviously, but I may.

Best, Flo