Is it possible to do Pio Test via WiFi?

Hello everyone, I am developing a platformio project consisting in adding automation to an IoT project with ESP32, the project itself is very simple, just consists in measuring temperature and humidity of a plant, but with additions to automatically deploy new firmware when the repository gets new code in main branch.

So the firmware is uploaded to the ESP32 device via OTA WiFi, and it could be done either with platformio IDE in VSCode, or with the workflow run of GitHub Actions. This is the repository link: GitHub - FeedehC/SmartPlant: Proyecto DevOps aplicado a ESP32 para monitorear condiciones de cultivo

Now I’m doing some tests with Unity (throwtheswitch’s framework), and the tests upload to the ESP32 via OTA WiFi (custom protocol with an extra script of python), but the tests don’t run because it needs to be connected via serial monitor (USB cable), when the USB is connected it works good.
The command used to test is “pio test -vv” in platformio terminal.

Is there any way to run tests on target (ESP32) via WiFi? I’m a beginner so any help would be appreciated, thanks in advance.

Technically you can make the serial output of an esp32 available to the outside world via WiFi via a telnet stream (library here) which you can point to as the test_port with a socket://<esp ip>:<port> syntax.

However, when the ESP32 is not directly attached, it becomes much harder to garuantee that you can always flash the firmware on it, since you can’t just reset it into bootloader at any time via the usb-serial adapter that’s connected to the chip. And even after the test firmware is done running, if you don’t ad OTAA capabilities to the testing firmware, you’ll have to reflash the next firmware via cable anyways. Same for when a test fails in some way and some piece of code hangs up the ESP32, making it inaccessible via WiFi or OTA. So I would never in my life recommend this technique to anyone.

Thanks a lot Max for your suggestions, how would you recommend to add unit tests to this project? May be not testing on target, just in a test runner, or maybe other approach.

Use two ESP32: One two run on-target rests on, the other one is your deployment target on which you only deploy the firmware after the tests have run successfully.

For giving the CI a board to test on, you can locally-hosted Github runners, or more generally, any computer with an ESP32 connected to it and running the PIO Remote agent, which is then accessible in the CI via pio remote test commands and friends.

1 Like

Thank you Max for your suggestions!

You need to implement your own CustomTestRunner. In the stage_testing connect to a remote device using any interface which is comfortable for you, gather test results and pass data to on_testing_data_output(data).

1 Like

I will implement that runner. I’ve read the documentation and couldn’t make the example work, if there is any other guide or post about this I would ask the link.
Thanks a lot for your guidance.

You need to implement custom testing framework and extend existing testing frameworks. See
https://docs.platformio.org/en/latest/advanced/unit-testing/frameworks/custom/examples/custom_unity_library.html