How do you test your flows?

Hi,

I have some quite complex Node Red automations. Being a SW developer, I want automated tests for all my flows so I can make sure things still work OK after I’ve modified them.

My current way of working is adding MQTT inputs to the beginning of my flows, and MQTT outputs at the end of them. Using a python script I then inject MQTT messages and wait for the expected output.

How are you testing your flows ?

1 Like

There is inject node and debug node in node-red.

How do you use that for automatic testing ?

I create inject every x minutes and when it is done if output compared to expected output isn’t expected it will output to debug node and send message via HA to telegram. Also on some nodes I use light-sheduler node.

Yeah, this is not what i am looking for :slight_smile:
I want to create a series of tests that can automtically test all my flows and reports an error on the commandline when something fails.

What do you mean by automatic? Timed? Triggered by something else?

I make a changes to a flow (not in my production environment) and run testcases (from the commandline or GUI) to verify that everything still works like I expect it to work. If all passes, I deploy the flow to my production environment.

The rest just creates flows, clicks in the UI and hopes everything just works? :slight_smile:

@devastator I like your idea. Have you found out anything interesting?

No, nothing …
I find this very strange TBH…

1 Like

@devastator have you tried asking this here?

I haven’t found the need to do that kind of testing. I’m curious as to how complex your flows must be like to make it worth your time to create test cases and have different environments…

I build my flows as smaller parts first, tested in the UI and then I connected them and do a test run of the whole flow if I think I need it. Otherwise I just deploy them as is.

Control for HVAC consists of like 50+ nodes…
Fan speed control based on:

  • anybody home ?
  • humidity
  • CO2
  • outdoor temperature
1 Like

This is also of interest to me. My flows are getting complex and with each update of node-red or HA I feel there may be a breaking change that ends up breaking the automation.
However, I think it’s too hard a problem to solve as what I really need is some feedback from HA to say a light was turned on when asked to - but not sure how to close that loop.

1 Like

If i like to test my flows I change the state of the object within Home-Assistant via the States tab under the development tools.

Could you share this setup?

This is probably not ideal but maybe if the logic was all in a function node that opens up all JavaScript test frameworks up for use. Of course, that defeats the main purpose of node-red which is to use the nodes!
As I type this I am also realizing that all node-red exports to JSON so maybe there’s a way to grab the export JSON from node-red and run it through a test.