Unit Testing for Arduino and ESP

I finally took the time to start learning how to write unit tests for Arduino/ESPs.

The first tests I wrote were for the button class. Even though I know in theory how to use it as was as time-consuming to get it started – one reasons why I delayed it quite a bit.

I used AUnit as a framework and the tests run on the devices (for now). I’ll look into abstraction with ExpoyDuino later – first steps first.
Some of my learnings: 

  • Memory is an issue on these devices (duh!). Some tests randomly did not work due to memory constraints. Took me a while to figure it out.
  • Execution speeds of the devices (ESP8266, ESP32, Uno, Nano) vary significantly. I had to increase buffer times for some devices because they were too fast at executing code, causing debounce times to be triggered.
  • After getting accustomed to it, writing the tests became quite fast. I went through the readme and wrote tests based on it.
  • A small annoyance – the execution order of tests is based on their name with AUnit – not the order found in code. So, I spent some time renaming groups and tests to have a decent order.

Next, I plan to add unit tests to the other two popular classes, ESPTelnet and ESPRotary.