Jump to ratings and reviews
Rate this book

Modern C++ Programming with Test-Driven Development: Code Better, Sleep Better

Rate this book
If you program in C++ you've been neglected. Test-driven development (TDD) is a modern software development practice that can dramatically reduce the number of defects in systems, produce more maintainable code, and give you the confidence to change your software to meet changing needs. But C++ programmers have been ignored by those promoting TDD--until now. In this book, Jeff Langr gives you hands-on lessons in the challenges and rewards of doing TDD in C++.

Modern C++ Programming With Test-Driven Development, the only comprehensive treatment on TDD in C++ provides you with everything you need to know about TDD, and the challenges and benefits of implementing it in your C++ systems. Its many detailed code examples take you step-by-step from TDD basics to advanced concepts. As a veteran C++ programmer, you're already writing high-quality code, and you work hard to maintain code quality. It doesn't have to be that hard.

In this book, you'll learn:


how to use TDD to improve legacy C++ systems
how to identify and deal with troublesome system dependencies
how to do dependency injection, which is particularly tricky in C++
how to use testing tools for C++ that aid TDD
new C++11 features that facilitate TDD
As you grow in TDD mastery, you'll discover how to keep a massive C++ system from becoming a design mess over time, as well as particular C++ trouble spots to avoid. You'll find out how to prevent your tests from being a maintenance burden and how to think in TDD without giving up your hard-won C++ skills. Finally, you'll see how to grow and sustain TDD in your team.

Whether you're a complete unit-testing novice or an experienced tester, this book will lead you to mastery of test-driven development in C++.

What You Need


A C++ compiler running under Windows or Linux, preferably one that supports C++11. Examples presented in the book were built under gcc 4.7.2.
Google Mock 1.6 (downloadable for free; it contains Google Test as well) or an alternate C++ unit testing tool. Most examples in the book are written for Google Mock, but it isn't difficult to translate them to your tool of choice.
A good programmer's editor or IDE.
cmake, preferably. Of course, you can use your own preferred make too. CMakeLists.txt files are provided for each project. Examples provided were built using cmake version 2.8.9.
Various freely-available third-party libraries are used as the basis for examples in the book. These include:

cURL
JsonCpp
Boost (filesystem, date_time/gregorian, algorithm, assign)
Several examples use the boost headers/libraries. Only one example uses cURL and JsonCpp.

368 pages, ebook

First published October 10, 2013

38 people are currently reading
223 people want to read

About the author

Jeff Langr

9 books9 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
62 (51%)
4 stars
47 (38%)
3 stars
12 (9%)
2 stars
0 (0%)
1 star
0 (0%)
Displaying 1 - 15 of 15 reviews
Profile Image for Zahra Dashti.
439 reviews126 followers
January 11, 2020
کتاب خوب و جامعی بود. شاید بیش از حد جامع :)) حتی مباحث غیر TDD رو هم کمی پوشش داده بود ولی نثرش خیلی کشش نداشت. مثالها رو اغلب دوست نداشتم، می تونست مثالهای جذاب تر و ساده تر بزنه. یه مشکل هم این بود که یه بخش رو با فریم ورک گوگل تست رفته یه بخش رو با یه فریم ورک دیگه! ولی در مجموع کتاب خوبه.
Profile Image for Yura Gavrilovich.
103 reviews7 followers
April 13, 2021
A good introductory book on TDD with C++ (at least for me with some background on Unit Testing everything was easy to understand). The first half of the book definitely worth reading, since it contains the ideas of the TDD cycle.
Rather outdated environment setup section and overall the book could've been shorter
Profile Image for Farsan Rashid.
36 reviews17 followers
October 9, 2018
Enjoyed a lot! Wide range of people can be benefited from the book.

Newcomer to TDD?
- Read it.
Familiar with TDD but want to improve?
- Read it.
Want to know how TDD can be used in legacy code?
- Read it.
Want to apply TDD in multi-threaded environment?
- Read it.

Though google's C++ unit testing framework (gmock) was used there is absolutely nothing that bars programmers of other programming languages to read it. This book teaches TDD in the light of clean code and best Object oriented practices. SOLID, Tell Don't Ask, Factory method pattern, Template method pattern and many more technique were discussed in order to teach refactoring phase of TDD.
I intend to re read the book in coming years as I skipped some chapters and need to solidify the techniques I learned. All in all I completely agree with Uncle Bob's review about the book.

Profile Image for Franck Brignoli.
1 review1 follower
January 20, 2022
Very good introduction (and refresher) to TDD. You do not have to know C++ to read it.
25 reviews
November 27, 2018
When I was looking for a next book to read, I wanted it to be about unit testing with a focus on test driven development and C++ and without repeating all the things found in an other excellent book, The Art of Unit Testing: With Examples in .NET. After looking around a bit, I stumbled upon this one, and I'm glad I did, as it turned out to be a lot more than I expected. Let's see it in a bit more detail.

The author starts with some details about the environment to be set up and the various tools and libraries one will need to use to get the uninteresting, yet necessary things out of the way as soon as possible. After that however, he gets down right to business without further ado with a very interesting problem, which is used to demonstrate how test driven development (TDD) can be used to solve it. This is an interesting approach, as there has been no discussion about TDD up until this point, but the author was very careful to make the example easy to follow even to those, who have never hear of any sort of testing before by making each step small and backed up with appropriate discussion. This chapter is also used to guide the reader through his/her first encounter with a unit testing framework, always explaining what does what and why, so no prior knowledge whatsoever is required.

At this point one could of course argue, that this in medias res approach is a bad way to start, but after reading the book, I'm actually convinced that this is the way to go, as the reader already has something real to relate to while going through the rest of the chapters, which include topics about test construction, test doubles, legacy challenges and threading and others. There is no shortage of code examples, which are is easy to follow at the beginning, but unfortunately this ease fades away for a while and then returns only closer to the end of the book. In order to be able to understand the harder to follow sections completely, one needs to download the accompanying code samples, but as of the writing of this review not everything compiles immediately due to some since deprecated features used in the examples. An update to the code base would definitely be nice have at this point, but with a little bit of reading fixing them is not rocket science either.

Apart from the topics mentioned earlier, the reader is also presented with some less technical, but nonetheless useful and important information on incremental design, quality of tests, sustaining TDD and avoiding some common pitfalls, how to actually decide what test to write next, metrics, practice possibilities, pair programming and more. The author also doesn't miss the opportunity to address some common concerns regarding TDD and the way code is written because of it by presenting quite solid arguments in favor of TDD, which I especially liked. So how can this book be compared to the other one mentioned at the beginning of this review? To be honest, I couldn't say which one is better, as both of discuss similar topics (though not identical), and there is an overlap between them (though not a 100%) because of it. Is the overlap bothering? Not at all, as the topics are presented in a different fashion, and as such they supplement each other's gaps pretty well.

With all these in mind, I'm pretty happy with this book, and I would most certainly recommend it even for those who already went through The Art of Unit Testing (or have some experience in TDD), and especially for those who have never read anything on the subject. It not only contains essential knowledge about TDD, but offers a lot more which will definitely broaden the view of the reader, but because of some minor caveats here and there I can't it maximal rating, although I was really thinking about it.
4 reviews
July 14, 2021
Very good book that takes the reader for a journey for a step-by-step implementation of TDD, using the GoogleTest framework as example. Using TDD, the author presents many ways on good software development practice, from code refactoring (as part of TDD) to the Ten-Minute rule, and from effective code coverage to continuous integration practice, to name a few.
The book also has a possible approach for adding tests to legacy code.
Profile Image for Daniel.
57 reviews
October 16, 2014
Practical advice to do TDD. C++ is just "an implementation detail".

I found the references really useful. Some of them I had already read and liked, some are now on my to-read list.

I'm just not sure if there is enough about C++, I don't know much about the language, so I it's ok that I felt like there was something missing.
Displaying 1 - 15 of 15 reviews

Can't find what you're looking for?

Get help and learn more about the design.