How to write testable C++ for Arduino

11 July 2020

testable c++ for arduino

Learn how to write reusable and testable C++ following the Inversion of Control principle. The new tutorial focuses on writing code for embedded systems (ESP32 MCU) and exercises are included for you to practice.

Creating software that is easy to unit test and can be reused, as-is, in different product variants and hardware platforms is one of the cornerstones of being agile. Us, embedded developers, often find excuses to prioritize the testable and, especially, reusable aspects of software in the name of performance and technical constraints (i.e. “it is too difficult design-wise”).
The former may be true sometimes. However such claims should be always taken with a grain of salt. Specifically, they should come with quantitative data that prove alignment with the business goals. To put it simply, don’t optimize for performance at the expense of other -ilities (e.g. maintainability, reusability, testability etc) unless the benefits are measurable and justified by the business.
In regards to the latter, one of the ways to write testable and reusable code is by following the Inversion of Control (IoC) principle. Check out this Youtube video to see how you can apply IoC in embedded systems: