Adam Fraser-Kruck
Test Your State Machine Monstrosities
Status: Coming up in April 2026!Let’s efficiently unit test and integration test our state machine monstrosities! The general approach works with multiple unit testing frameworks, but Google Test has some distinct advantages, so we’ll use that. We’ll laugh, we’ll cry, and in the end, we’ll achieve full hierarchical state transition and behavior coverage in an easy-to-maintain manner.
The general concept works with any type of state machine (hand written, code generated, C, C++, Python…).
Topics include:
- “Hand of God” vs “natural flow” testing — pros and cons
- Unit testing and integration testing approaches
- Testing embedded C state machines
- Testing embedded C++ state machines
- Spies, fakes, mocks, and stubs
- Google Test tips: fixtures, mocks, scoped traces, and more
Visualize Your State Machines
Status: Available NowLet's dive into state machines by building an embedded security system!
Important Info
You should probably view my presentation as two parts:
- First half = introduction
- Second half = advanced
The first half provides a nice intro to visualizing state machines and using StateSmith with PlantUML. If all you want is some introductory info, it's OK to stop here :)
The second half starts to get more advanced and provides exclusive content to Embedded Online Conference attendees. It goes above and beyond what is already available in free StateSmith tutorials. I would highly recommend downloading the example project and following along (pausing when needed).
Presentation Description
State machines are an incredibly helpful pattern for embedded systems, but hand-coded state machines can be difficult to understand and maintain, especially as designs become more complex with additional states and transitions.
To make our lives easier, we are going to use StateSmith to visually model our state machines in PlantUML.
StateSmith is a cross-platform, free/open source tool for generating state machines in multiple programming languages (C, C++, C#, Java, Python, JavaScript, TypeScript). The generated code is human-readable, has zero dependencies, and is suitable for use with tiny bare-metal microcontrollers, video games, apps, web, computers, and more. It avoids dynamic memory allocations for those focused on safety or performance. Each state machine instance only requires a single byte of RAM.
We'll start by creating a simple button state machine that performs debouncing and long press detection. Then we will connect those button state machines to our Control and Display state machines.
Every step of the way, we will simulate our design using Wokwi (an online electronics simulator) so that you can easily follow along without any physical hardware.
Helpful Links
I'm happy to answer questions here, on GitHub or Discord.
Got any interesting state machine stories to share? I'm always interested :)
