When you’ve got more than the simplest embedded program for Arduino (or any other framework), it becomes much harder to test that it’s working properly by purely running it. For something like Blink, testing is simple because all we need to do is upload it and see the LED turn on and off; there’s little risk of missing anything significant. However, let’s skip forward to a menu based application with Serial or Ethernet control, there is very little chance that you’d catch all the edge cases by manual testing.
Sometimes the situation arises where a product is built (or gets close to being built), before any concerns about it’s stability are discussed or proper planning arranged. Often this leads to code being written without any proper test plan in place. Combined with very tight deadlines there’s often even no plan to go back and fix things up. Once this situation occurs, it’s probable that the product release will be compromised.
This article discusses how to unit test a simple project with Arduino, if you’re not used to writing unit tests, or need more background, then first read this guide on unit testing embedded projects. My favoured library for writing unit tests on Arduino platform is AUnit. It is open source, under a commercial friendly MIT license and provides a nice API. It is available from here: AUnit is available through library manager, just install it direct from the IDE.