---
title: "Test Driven Development with C++: Much harder than it should be"
url: "https://osherove.com/blog/2004/12/2/test-driven-development-with-c-much-harder-than-it-should-be.md"
canonical: "https://osherove.com/blog/2004/12/2/test-driven-development-with-c-much-harder-than-it-should-be.html"
published: "2004-12-02T16:50:00"
updated: "2004-12-02T16:50:00"
tags: ["Agile Related"]
author: "Roy Osherove"
description: "(BTW: Does anyone have any knowledge of the C++ testing frameworks listed here at the bottom of the page? Got any favorite?) One of the things I'm doing right now in Magen is helping a company that uses hard core C++…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Test Driven Development with C++: Much harder than it should be

By Roy Osherove December 2, 2004 In [Agile Related](https://osherove.com/blog/category/agile-related)

**Historical article** · Originally published December 2, 2004; technical details may be outdated.

_(BTW: Does anyone have any knowledge of the C++ testing frameworks_ [_listed here_](http://tejasconsulting.com/open-testware/feature/unit-test-tool-survey.html) _at the bottom of the page? Got any favorite?)_

One of the things I'm doing right now in Magen is helping a company that uses hard core C++ for various networking and conferencing software move to a more agile oriented development regime. As part of that they are learning Test Driven Development - in C++. There are a few things I can say about this. Mainly that it's a struggle all the way through.

The fact is that I've never been a C++ wonk and so I'm having some difficulty adjusting to the way things are done in in this language. Add to that that:

- [CPPUnit](http://cppunit.sourceforge.net/) is the framework of choice for C++ (at least that I know of).
- There are no refactoring tools for C++
- Visual C++ 6.0 is horrendous to work with. Lack of usability is apparent in everything.

Some of the early conclusions so far:

- Creating unit tests in C++ is done by inheritance (no attributes to speak of) and by using special macros to manually add your test cases and test fixtures into the unit test runner
- The only way we could figure out so far on how to run the unit tests is by manually using the test runner objects from within the main method (which means we are bound to using a console application)
- Documentation on how to make a project that uses the GUI test runner is practically non-existent. Only a small sample comes with CPPUnit and it's hard to decipher.
- It pretty much works the same way like NUnit but you have much less
    - types of assertions
    - "attributes" for example, no such thing as testFixtureSetup or TestFixtureTearDown methods to override from the base class
    - ease of use - at least 4 steps needed to create a new unit test

So overall this leads to some facts:

- If its harder to write tests in C++, less people are likely to do it.
- If it's harder to refactor code, less people will do it (this is more an issue with the tools - VC++ 6.0)
- Agile wok in C++ is **much harder** but I can honestly say **it does not have to be**.

Sadly it doesn't look like there's any sort of agile innovation in this territory. CPPUnit is not getting any new features soon, and something like the NUnit-Addin in C++ is nothing but a dream. That sucks because there is **a lot** of code out there being written in C++. Has this suddenly become some sort of "second class" platform for agile tools? If so it could have some sort of explanation. Mainly that could be that when going agile you want as much productivity as you possibly cam and so automatically turn to RAD-oriented tools and IDEs. C++ has never been considered as such. But that could change.

If an Add-in like [Visual -Assist](http://www.wholetomato.com/) is so smart, it could easily add refactoring features to the platform. CPPUnit and variants cold be written to more easily run form a GUI. More and better documentation and blogs could be written on these issues.

And to finish off, here's something I found on my search for a Mock object framework for C++ .

[This guy tells it like it is](http://binkley.blogspot.com/2004_10_01_binkley_archive.html) and one could easily replace "Java" with ".Net":

_"What happened to the joy of C++? And wasn't_ [_the moo book_](https://www.amazon.com/exec/obidos/tg/detail/-/0201423391/103-2951998-3557461 "ruminations on c++ : a decade of programming insight and experience") _a gas? Clearly_ [_I enjoy the stuff_](http://binkley.blogspot.com/2003/09/proxied-data-members.html "proxied data members")_. But now I hate C++. The explanation is easy: tools._

_After a solid year of_ [_Java at its finest_](http://blogs.thoughtworks.com/ "thoughtblogs")_, returning to C++ and no good unit test libraries (_[_CPPUnit_](http://cppunit.sourceforge.net/) _being about it), no_ [_mock objects_](http://easymock.org/)_, no_ [_IDEA_](http://www.jetbrains.com/) _or decent_ [_Eclipse support_](http://www.eclipse.org/)_, no_ [_ant_](http://ant.apache.org/) _or_ [_maven_](http://maven.apache.org/)_, no_ [_good coverage tools_](http://www.jcoverage.com/)_, no good code analysis, no_ [_good dependency analysis_](http://www.clarkware.com/software/jdepend.html) _on and on and on. **Tools make the programmer.** And C++ has dog food for tools compared to the wealth of open-source projects for Java. Now that I'm working on a C++ project, my development efforts are at least doubled for the same work, and I continually feel that I am leaving imporant parts of_ [_best practices_](http://extremeprogramming.org/) _out of the picture. Nor does it look like that's about to change anytime."_

_\[update: looks like people_ [_are actually looking for Agile C++ developers_](http://www.braithwaite-lee.com/weblog/2004/07/wanted-agile-c-wizard.html)_. I bet those are really hard to find these days\]_

## More in Agile Related

[All posts in Agile Related](https://osherove.com/blog/category/agile-related)

- Dec 2, 2004

    ### [Nice Agile blog](https://osherove.com/blog/2004/12/2/nice-agile-blog.html)

- Dec 2, 2004

    ### [Test Driven Development proves useful at Google](https://osherove.com/blog/2004/12/2/test-driven-development-proves-useful-at-google.html)

- Nov 29, 2004

    ### [Test Driven Development workshop news and coming attractions](https://osherove.com/blog/2004/11/29/test-driven-development-workshop-news-and-coming-attractions.html)

- Nov 29, 2004

    ### [TestDriven.Net version 1.0 is out (with a new site design as well)](https://osherove.com/blog/2004/11/29/testdrivennet-version-10-is-out-with-a-new-site-design-as-we.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
