STlink unit testing not working, asking me for test_port

I am trying to conduct unit tests in Unity. I am using a STlink device to connect my blackpill development board. I have uploaded code successfully, but I wanted to write tests this time. I keep getting an error that asks me to Please specify test_portfor environment or use global–test-port option., I checked my device manager and see that my STlink has no COM port associated with it. If I give it a random test_port, which results in a “passed” test. But it fails to detect any test cases. I have attached pictures of my .ini file, test cases and output.




Anything of help here?

Cheers,
Norm.

It is true that you can transport arbitrary data via semihosting (SWDIO + SWCLK) or single-wire-output (SWO) to the ST-Link.

However, the default “unit test data transport code” PlatformIO supplies for framework = arduino is to use the Serial object, aka the first hardware UART or USB serial if activated. Thus there is exactly 0 happening on the SWD lines after the test firmware is flashed, currently.

PlatformIO does however also provide an example project and documentation for transporting the unit test via semihosting, thus only needing an ST-Link adapter (or similiar debug probe) connection, as you currently have it.

https://docs.platformio.org/en/latest/advanced/unit-testing/semihosting.html

If you don’t want to go that way, you can also enable the USB-serial functionality of your board (build_flags and options from docs). Given that you’re not double-powering your board (e.g. with the USB cable plugged into the USB port of the dev board, there should be no 3.3V connection between the ST-Link and the board), you can thus use usb-serial as normal to run the unit test. The only tiny caveat is that you need a delay after upload (for the USB init time) as described here.