TDD for C++ Programmers

by Jeff Langr

April 26, 2012

Recently I’ve been getting a good number of calls from C++ shops interested in doing TDD, despite my heavy Java background. I took on some of the business and had to turn away some to avoid being swamped. Many other folks I know (name dropping time!)–Tim Ottinger, James Grenning, JB Rainsberger, others–have also reported doing C++ work recently.

Is TDD finally taking hold in C++ shops? Does TDD even make sense for C++? I think so, and two current customers believe they’ve been seeing great benefits come from applying it. Building and delivering a C++ TDD course recently helped me come back up to speed in the language to the point where I was comfortably familiar with all of the things I hated about it. 🙂 It makes no sense to take such a difficult language and stab at it without the protection of tests.

I’ve been simultaneously writing more (after a typical winter writing freeze) and looking at Erlang–a much cooler language, challenging in a different kind of way. Meanwhile, my editor at PragProg has been asking for new book ideas. Here were some of my thoughts:

  • Refactoring 2012

  • Modern OO Design (not template metaprogramming!) / Simple Design

  • Object-Oriented Design “In a Flash” (card deck, like Agile in a Flash)

No matter how hard I try to run screaming from C++, there it is right behind me. It’s indeed a powerful language, and there is gobs and gobs of code written in it, and it’s about time we started trying to figure out how to make the best of it. It’s not going away in my lifetime. I also think C++ programmers are not well-served in terms of writings on TDD out there.

So… I decided it was going to be TDD in C++. Tim Ottinger and I put together and just sent out a proposal for a book tentatively named TDD for C++ Programmers (with a catchy subtitle, no doubt). We hope there’s enough demand and interest to get the proposal accepted. If all goes well, we’ll be soliciting reviewers in a few weeks.

I look forward to writing again with Tim! More in an upcoming blog post about our collaborative writing experience.


EL May 8, 2012 at 10:30 am

Coming from Ruby, I’d definitively buy this book to be more confident when coding in c++!

Jeff Langr May 8, 2012 at 11:11 am

That’s an interesting direction. My sympathies. 🙂

Jeff Langr June 26, 2012 at 9:03 am

Update: Now seeking a new co-author. Tim won’t be able to co-author due to other pressing concerns and corporations. Please drop me a line if you have any interest in co-authoring.

Pingback: TDD Is Not Mindless |

Robert Gleeson September 6, 2012 at 10:39 pm

Another person coming from Ruby. I’m looking to branch into other languages, C++ is on the list and I think this could be a awesome companion book to another book that teaches C++.

AIK March 6, 2013 at 3:49 am

Hi Jeff,

I saw your “TDD for C++ Programmers” as an upcoming beta in the Pragmatic Bookshelf site. Any chance of me being able to get an advance copy(for the price of course?). I have been reaping many benefits from Grenning’s TDD for Embedded C book, so can’t wait to see what you have to say on TDD for C++. If you wish, I could review it too :).

Thanks in advance

Jeff Langr March 6, 2013 at 7:48 am


Send me an email, I’ll add you to the review group.

The book will be in beta in a few weeks, presumably.


sunday June 15, 2014 at 6:33 pm

Sharing here as this may save someone some grief.
To fix linker error related to pthread, in CMakeLists.txt move ‘target_link_libraries(test pthread)’ line to the end of the file.

Share your comment

Jeff Langr

About the Author

Jeff Langr has been building software for 40 years and writing about it heavily for 20. You can find out more about Jeff, learn from the many helpful articles and books he's written, or read one of his 1000+ combined blog (including Agile in a Flash) and public posts.