HABApp icon indicating copy to clipboard operation
HABApp copied to clipboard

Improve testability

Open DerFetzer opened this issue 1 year ago • 4 comments

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.

DerFetzer avatar Apr 03 '23 22:04 DerFetzer

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

spacemanspiff2007 avatar Apr 04 '23 04:04 spacemanspiff2007

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.

DerFetzer avatar Apr 04 '23 14:04 DerFetzer

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.

spacemanspiff2007 avatar Apr 04 '23 17:04 spacemanspiff2007

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.

DerFetzer avatar Apr 04 '23 20:04 DerFetzer