How to write testable and reusable C++ for Arduino, following the Inversion of Control principle.
This is the repository for the material included in the How to write testable C++ for Arduino video tutorial.
The tutorial demonstrates how to design and refactor C++ according to the Inversion of Control
principle (IoC), using Arduino compatible code as an example. To follow along, it is advised you
clone
the repository and open it in an code editor.
- Calculator resources and test
- MagicCarController sketch
- MagicCarControllerTestable resources and test
During the tutorial, you are tasked to complete the following tasks so to get hands-on practice with unit testing for Arduino:
- Finish the tests for the Calculator sketch.
- Finish the tests for the MagicCarControllerTestable sketch.
Once you are done, you can try evolving the code further and experimenting with the following stretch tasks:
- Write more unit tests to cover more edge cases.
- Inject the lightsPin instead of hard-coding it.
- Decouple the RestServer interface further from the ESP32
WebServer
implementation and refactor the code as well as the tests accordingly. - Think of a better way to return an Arduino
String
in a platform-agnostic way.
The solutions can be found in the solutions branch.
Do you have a solution that you want to share with us? Then fork this repository, push your solution to it
and then let me know by opening an issue. I will add a link to your repo in this README
file.