Example of BDD Style TDD For Embedded System Software
Based on the blog post https://www.embeddedrelated.co
BDD adds several advantages to TDD:
- It results in an executable specification of a module that is understandable by both technical and non-technical stakeholders. This makes it easier to understand by all parties, and easier for them to specify additional behavior.
- Because of its emphasis on behavior, it guides the developer to test to interface, not internals. This minimizes the risk of creating brittle tests. That minimizes the need for test maintenance when doing production code maintenance: changing the internals doesn't create a mass of failing tests.
- It focuses on one aspect of behavior at a time. This ensures that tests only test one thing at a time, keeping them simple. When a test fails, it's clear what failed and what should have happened. That makes isolating and fixing the problem faster.
- It avoids code bloat and untested code, since every bit of production code is there because a behavioral test required it.
This additional layer of discipline makes TDD even more effective for both immediate development and long-term maintenance. It's easily applied to embedded systems modules to enable off-target testing, resulting in known-good components. It works equally as well when you start with a well-defined idea of what the module internals will be and when you only have a vague idea.