TDD is a modern programming practice C developers need to know. It's a different way to program–unit tests are written in a tight feedback loop with the production code, assuring your code does what you think. You get valuable feedback every few minutes. You find mistakes before they become bugs. You get early warning of design problems. You get immediate notification of side effect defects. You get to spend more time adding valuable features to your product.
James is one of the few experts in applying TDD to embedded C. With his 1.5 decades of training, coaching, and practicing TDD in C, C++, Java, and C# he will lead you from being a novice in TDD to using the techniques that few have mastered.
This book is full of code written for embedded C programmers. You don't just see the end product, you see code and tests evolve. James leads you through the thought process and decisions made each step of the way. You'll learn techniques for test-driving code right next to the hardware, and you'll learn design principles and how to apply them to C to keep your code clean and flexible.
To run the examples in this book, you will need a C/C++ development environment on your machine, and the GNU GCC tool chain or Microsoft Visual Studio for C++ (some project conversion may be needed).
Review By: L. John Ribar 02/09/2012Test-Driven Development for Embedded C by James W. Grenning is one of the best books I've read for learning the ins and outs of test-driven development (TDD). While it is especially suited for those who work in an embedded environment, I recommend this book highly to any C or C++ programmer who is trying to understand and correctly implement TDD practices.
Grenning is the author of the CppUTest unit testing platform for C++ programmers. He references this package, along with a C-only tool called Unity, in his discussion of using tools and learning the TDD process.
The book covers the basics of TDD, including how to get started with each of the testing platforms, and uses real-world examples to walk through the implementation of these techniques. It is sprinkled with quotes and discussions from other well-known programmers.
The book is written for the TDD beginner but, at only 350 pages, it is a good reference for those who use TDD on a regular basis as well.
I appreciate Grenning’s style and attitude. With the lead-in statement "TDD is structured procrastination," Grenning explains our desire to put off writing the right production code until the tests force us to. Completeness follows only when all the tests are in place. To remember this, he suggests using the "Do you have a test for that?" standard. No production code should be written until a test is in place to make sure it works.
The book covers many useful topics, including dependency injection, DRY (don't repeat yourself), refactoring, strategies in embedded situations, test doubles and mock objects, and common questions and answers about implementing TDD in your own situation. In addition, each chapter ends with a "Put the Knowledge to Work" section, giving you the opportunity to implement the techniques you've just learned and greatly improve the code you've been using to test.
Perhaps the importance of using TDD can be best summed up with this statement: "Think of 100 reasons why TDD could never work for you. Then, go review your bug list."
If you are looking to implement TDD in a C or C++ environment, this is a great place to get started. It is a book I wish I had years ago when I first started working with TDD concepts. This would have brought me up to speed faster and with a better foundation of knowledge.