PlatformIO Community

Tracing inside of unit tests

Hi Everyone

I’m trying to find a TDD workflow that works for me with PlatformIO. I’ll try to explain what I’m trying to achieve:

When I run my test suite (on my an Arduino Nano), if one of the tests fails, I want to isolate that test (this works fine) and run it again, this time with tracing enabled.

I put sensible tracing commands in the source code to quickly determine - at a glance - why a specific test and/or function is failing. I’m explicitly not looking for a step-debugging solutions, as I think tracing suits my needs best in the case.

In other words: I’m trying to log information from inside of a unit test back to my laptop where I issued pio test.

Right now I’m getting an exception when some tracing happens, as that tracing tries to write to the serial line (i’m using from Adruino.h - Serial.println(…)) :

...
serial.serialutil.SerialException: GetOverlappedResult failed (PermissionError(13, 'Toegang geweigerd.', None, 5))

Is the above workflow possible with PlatformIO’s built in unit testing support?

Is there an interface to use the pio test transport and log back to the laptop?

If not, is there a way to achieve this through a third-party library, that plays nicely with PlatformIO?

Ok. So I think I can use Unity’s TEST_MESSAGE macro to achieve this.

Adding a single TEST_MESSAGE("log this"); call to my code ended up correctly in the output of pio test

I’m assuming this will not break parsing of the transport’s stream by pio test

This worked perfectly. Both running the tests on the Arduino, and running them on Native.