spacemanspiff2007 / HABApp

Easy home automation with MQTT and/or openHAB
Apache License 2.0
54 stars 23 forks source link

Improve testability #369

Open DerFetzer opened 1 year ago

DerFetzer commented 1 year ago

This takes ideas from nobbi1991 and extends them with a time-aware scheduler.

Goal is to simplify testing of user rules. I implemented an example in habapp-rule-test-demo. watch_change is not working at the moment since it seems to use a different mechanism.

spacemanspiff2007 commented 1 year ago

I think the rule factory is a nice idea. We could have something like create_rule(SimpleRule, 'p1', 2) which will do SimpleRule('p1', 2) in normal cases and during testing it won't create anything. What do you think about something like that? Obviously I'd implement it using pytest since this is what HABApp uses so the fixtures can be shared

DerFetzer commented 1 year ago

I think the rule factory is a nice idea. We could have something like create_rule(SimpleRule, 'p1', 2) which will do SimpleRule('p1', 2) in normal cases and during testing it won't create anything. What do you think about something like that?

Sure, we could do that. What do you think would be the best way to figure out if we are running tests or not? In the demo repo I am using an environment variable. Maybe we could do something similar.

Obviously I'd implement it using pytest since this is what HABApp uses so the fixtures can be shared

I am not familiar with pytest but I'll figure it out.

spacemanspiff2007 commented 1 year ago

I am not familiar with pytest but I'll figure it out.

No worries - this issue is more like a brainstorming issue to create a good concept and evaluate some ideas. I by no means expect you to implement this and modify all existing test cases yourself. I'll do the heavy lifting myself but I'd rather have a good concept first instead of quickly implementing something that is not properly thought through. And for that I'll appreciate any input.

Have you found the ability to progress in time useful? I'd have expected these tests are more like an input -> expected output black box.

DerFetzer commented 1 year ago

No worries - this issue is more like a brainstorming issue to create a good concept and evaluate some ideas.

:+1:

Have you found the ability to progress in time useful? I'd have expected these tests are more like an input -> expected output black box.

I see this as a very important aspect because I do want to test as much of my rules as possible. And most of them need some kind of temporal behavior.