Hi everyone! I am struggling with unit testing, and I am slowly losing my will to live… I use PIO (Core 4.3.4 Home 3.2.3) in VScode (1.47.0) on a 64 bit Windows 10 machine. I am working on a firmware project that uses an Arduino Micro and an Arduino Mega for prototyping (it’s a master-slave system).
A while ago, I started investigating unit testing for that project, and after much wailing and gnashing of teeth and a lot of googling I finally managed to get tests running on my Mega. Now, I am trying to run tests on my Micro. I created a test file much the same as my Mega test file, I run the Test task, the tests compile and the upload starts, but then the Micro disappears from Device Manager, never to be heard of again. No LED, nothing. if I reset it, it goes into the bootloader, but once that times out, it’s gone again. Here’s my ini:
[env:micro]
platform = atmelavr
board = micro
framework = arduino
I think this problem is caused by the fact that the Micro uses a native USB connection rather than UART for serial communication. I can recover the board by resetting it and flashing a blink script while the bootloader is still there.
Fine, I thought, you are really supposed to write your business logic platform independent, and do unit tests natively. So I set out to do just that. However, this time, after much googling and searching this forum, reading the docs and studying the examples, I still can’t get any tests to run. My library uses no AVR headers so it should compile just fine for x86. The native
platform doesn’t work at all. I only get:
Building...
'cc' is not recognized as an internal or external command,
operable program or batch file.
*** [.pio\build\native\test\output_export.o] Error 1
'cc' is not recognized as an internal or external command,
operable program or batch file.
*** [.pio\build\native\UnityTestLib\unity.o] Error 1
I also cloned the calculator example and tried to run the native unit tests, same result. No dice.
So I tried to use x86 as platform. First I ran into the test_transport problem, but I managed to figure this out by exactly following the docs. Alas, the rejoicing was brief, because now I get:
Building...
Uploading...
*** Do not know how to make File target `upload' (C:\git_repositories\combivalve_firmware\CombiValve_firmware\upload). Stop.
And I could not figure this one out yet. I’m stuck, and such is my despair that going back to Atmel Studio is being considered.
So, I have three questions, really. First, can anyone tell me how to run my unit tests on my Micro? Second, can someone tell me how to run my unit tests on Windows?
And third, can anyone recommend a guide or some docs for the whole unit testing business that is actually useful? The examples that are there are really cute and all, but after spending A LOT of time trawling through the PIO docs and example repos and reading blog posts, I still can’t figure out how to make my own unit tests work. I might be a bit daft, in fact, that’s a real possibility, but continually running against walls gets really frustrating. I’d REALLY appreciate a good how-to…