Intro to Embedded Rust Part 9: Test-Driven Development | DigiKey @digikey
Intro to Embedded Rust Part 9: Test-Driven Development | DigiKey  @digikey
Uploaded March 2026 | Updated November 2026, 17 hours ago
In this video, we cover test-driven development (TDD) for embedded Rust by demonstrating writing a unit test for our previous TMP102 temperature sensor driver library (crate) and a simulated I2C bus known as a “stub.”
The written guide for this episode can be found here: digikey.com/en/maker/tutorials/2026/intro-to-embedded-rust-part-9-test-driven-development
The GitHub repository containing the Docker image and example code for this series can be found here: github.com/ShawnHymel/introduction-to-embedded-rust
Test-driven development is a professional software methodology where you write tests before implementing functionality, helping catch bugs early and ensuring code meets requirements. While TDD is common in application development, it presents unique challenges in embedded systems where code runs on hardware and interacts with peripherals like I2C, SPI, and GPIO.
See here to learn more about Continuous Integration/Continuous Delivery (CI/CD): youtube.com/watch?v=1nxGcfIm-TU&list=PLEBQazB0HUyR00bgoctk-5uZoOrbmPASC
This tutorial demonstrates how to write unit tests for our TMP102 temperature sensor driver that run entirely on your development computer without requiring a Raspberry Pi Pico 2, sensor hardware, or any embedded target. You'll learn how to create stub implementations of embedded-hal traits, use Rust's testing framework with cargo test, and apply TDD principles to embedded driver development for reliable, maintainable code.
This hands-on embedded testing tutorial covers the complete TDD workflow and testing concepts essential for professional development. We explain the red-green-blue cycle: writing failing tests first (red phase), implementing code to make tests pass (green phase), and refactoring for quality (blue phase). We cover the three levels of testing: unit tests for individual functions, integration tests for component interaction, and system/end-to-end tests for complete applications. We also define common test substitution terminology including dummies (placeholders), fakes (working but simplified implementations), stubs (predetermined responses), spies (recording call information), and mocks (verifying correct usage). We focus on using stubs and dummies to simulate I2C communication without real hardware, enabling fast, automated testing during development.
We put these concepts into practice with a demonstration: creating a test infrastructure for the TMP102 driver library along with two unit tests. We cover how to use the #[cfg(test)] attribute to include test-only code that doesn't compile into production builds, and how to access the standard library for testing while keeping your library no_std for embedded targets.
We build an I2cStub struct that implements the embedded_hal::i2c::I2c trait with configurable responses, allowing you to set predetermined temperature values and verify driver behavior. You'll see how to write test functions with #[test] attributes, use assertions like assert_eq! to verify behavior, and run tests with cargo test command.

Related Link:
digikey.com/en/maker/tutorials/2026/intro-to-embedded-rust-part-9-test-driven-development

Links:
Getting Started with STM32 and Nucleo: youtube.com/watch?v=hyZS2p1tW-g&list=PLEBQazB0HUyRYuzfi4clXsKUSgorErmBv
Introduction to Real-Time Operating Systems (RTOS): youtube.com/watch?v=F321087yYy4&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz
Raspberry Pi Pico 2: digikey.com/en/products/detail/raspberry-pi/SC1631/24627142
Intro to CI/CD: youtube.com/watch?v=1nxGcfIm-TU&list=PLEBQazB0HUyR00bgoctk-5uZoOrbmPASC

Learn more:
Maker.io - digikey.com/en/maker
DigiKey’s Blog – TheCircuit digikey.com/en/blog
Connect with DigiKey on Facebook facebook.com/digikey.electronics
And follow us on X: https://x.com/digikey

Product:
digikey.com/en/products/detail/raspberry-pi/SC1631/24627142
digikey.com/en/products/detail/raspberry-pi/SC1632/26241102
digikey.com/en/products/detail/raspberry-pi/SC1633/25862735
digikey.com/en/products/detail/raspberry-pi/SC1634/26241087
digikey.com/en/products/detail/sparkfun-electronics/13314/6797646
digikey.com/en/products/detail/lite-on-inc/LTL-4224/217584
digikey.com/en/products/detail/stackpole-electronics-inc/CF14JT220R/1830334
digikey.com/en/products/detail/te-connectivity-alcoswitch-switches/1825910-6/1632536
digikey.com/en/products/detail/dfrobot/FIT0096/7597069
digikey.com/en/products/detail/adafruit-industries-llc/1957/6827090
digikey.com/en/products/detail/cvilux-usa/DH-20M50055/13175849

Chapters:
0:00 Intro
0:51 Overview of Test-Driven Development (TDD)
4:55 Implement I2C Stub
19:25 Write Unit Tests
23:33 Run Unit Tests
26:14 Conclusion
Intro to Embedded Rust Part 9: Test-Driven Development | DigiKeyCreate Bare Infill Shapes for 3d Printing #Tip #3dprinting #Design #MakerUpdate5 Bonus Maker Projects #3dprinting #DIY #Electronics #MakerUpdate5 Bonus Maker Projects #DIY #Electronics #Project #MakerUpdateTeardown tools you won’t want to put down - Electronics with Becky Stern | DigiKeyNXP S32M2™ Motorized Ice Cream Maker – Potentially Genius® | DigiKeyUnlock Your K40 Laser Cutter with This Free Tool #lasercutter #software #DIY #MakerUpdateWhy Your LEDs Dont Match - Electronics with Becky Stern | ShortWhat is a software defined radio and why would I want one? - #thebytesizedengineer | ShortHeat Shrink Basics - Electronics with Becky Stern | DigiKeyAutomotive vs. Mobile Robots #DigiKey #LetsTalkTechnical #onsemiRandom Fun [Maker Update] | Maker.io
DigiKey |

Intro to Embedded Rust Part 9: Test-Driven Development | DigiKey

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER