Unit testing communication between devices

I’m very new to unit testing. I have unit testing working on an embedded device. I can test my classes appropriately for various conditions…

However, my use case involves networking between arduinos using PJON (GitHub - gioblu/PJON: PJON (Padded Jittering Operative Network) is an experimental, arduino-compatible, multi-master, multi-media network protocol.) which works well… but I have a whole bunch of layers that I’d like to test which involves sending and updating values between arduinos.

My current project has several of these ENV with build src filters for each arduino.

[env:mega_A_LEDS]
platform = atmelavr
board = ATmega328P
framework = arduino
upload_port = /dev/ttyUSB4
monitor_port = /dev/ttyUSB4
test_port = /dev/ttyUSB4
monitor_speed = 115200
build_src_filter = +<./${PIOENV}/*.cpp> +<./${PIOENV}/*.h>
build_flags = 
  ${env.build_flags}
  -D PJON_INCLUDE_SWBB
  -D PJON_ID=5
  -D PJON_PIN=2
  -D PJON_WAKE=3
  -D LED1_PIN=14 
  -D LED2_PIN=15
  -D LED3_PIN=16
  -D ENABLE_LEDS=4
  -std=gnu++11
lib_deps = 
  ${env.lib_deps}
build_unflags = 
  -Wregister
  -std=gnu++17

Ideally I need the test to build two binaries and upload them to different arduinos… say A and B… and the test to involve sending a message from A to B…

You might want to orchestrate this integration or end-to-end test on a higher level. Unit testing is just that: Testing small units of code. Things like the Robot Framework can do that. You can have it call into pio run -t upload -e <environment> to prepare uploading binaries to both boards, then agree on some instrumentalization / command protocol so that you can each send device A and B some data, or query some data, which the Robot tests can then trigger and query to check if data arrived from point A to point B correctly.

Still, the unit tests at the lowest level will still be there to check the basics.

1 Like

That is a good idea, I will look into it.

Thank you