No serial output at unit tests on Arduino Uno with Unity in MS VSCode in contrast to Arduino Mega and ESP8266

Unit tests with Unity on Arduino Uno even trivial ones do not produce any serial output in the terminal, neither after recommended board reset, but just open serial port and never close it. No combination of monitor_rts and monitor_dtr in the environment of the platformio.ini does not help.

The same unit tests on Arduino Mega 2560 or ESP8266 run and output correctly.

Steps to Reproduce

  1. Make trivial unit test, e.g., “test_experiment/experiment.cpp”:
#include <Arduino.h>
#include <unity.h>
void test_experiment(void)
{
  TEST_ASSERT_EQUAL_INT(4, 4);
}
void setup()
{
  delay(2000);
  UNITY_BEGIN();
  RUN_TEST(test_experiment);
  UNITY_END();
}
void loop() {}
  1. Make environment, e.g., “dev_uno” in platformio.ini:
[env:dev_uno]
platform = atmelavr
board = uno
framework = arduino
test_filter = test_experiment
  1. Run unit test:
platformio.exe test --environment dev_uno

Actual Results

Processing test_experiment in dev_uno environment
-----------------------------------------------------------------------------------------------------------------Building & Uploading...

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file ".pio\build\dev_uno\firmware.hex"
avrdude: writing flash (3178 bytes):

Writing | ################################################## | 100% 0.49s

avrdude: 3178 bytes of flash written
avrdude: verifying flash memory against .pio\build\dev_uno\firmware.hex:
avrdude: load data flash data from input file .pio\build\dev_uno\firmware.hex:
avrdude: input file .pio\build\dev_uno\firmware.hex contains 3178 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.38s

avrdude: verifying ...
avrdude: 3178 bytes of flash verified

avrdude: safemode: Fuses OK (E:00, H:00, L:00)

avrdude done.  Thank you.

Testing...
If you don't see any output for the first 10 secs, please reset board (press reset button)

Additional info

With Arduino Uno after running the unit test resseting the board does not help and the serial port stay still opened, so that some serial clients state at opening that port, e.g.:

  • Serial Monitor VS Code Extension: Failed to open the serial port COMxx.
  • MobaXterm (Putty): Opening ‘.\COMxx’: Error 5: Access is denied.