Reputation: 13135
I do test driven development of c++ code and one thing I find awkward is the fact that I need to create many files for each class, for example:
iread.h read.h read.cpp mockread.h mockread.cpp testread.h testread.cpp
And add these to different folders (filters) within my project.
As a result, I've abondand cpp files to a large extent. However this breaks the rule that unit tests should be as quick as possible to build. So I wish to stop doing this if I could only speed development up on other fronts.
To cut to the point, I literally get a headache when I work with test driven development in C++ due to the housekeeking overhead. I don't have the same problem when working with python.
One improvement I've recently made is to use google mock and to create the mocks automatically from their interfaces. So this is certainly an improvement.
However it feels that I should be able to reduce the overhead further through the use of plugins which automatically create stubs for all the classes I need when tdding a particular class. Do such plugins exist? Would it be difficult to develop such a plugin, with regard to Eclipse, VS 2005, VS 2008 and VS 2010 (Sorry, but I have to work in different environments from time to time).
Another issue is the amount of navigating I need to do in order to find classes (mocks, tests, etc) for a given class under test in the Project Explorer (as it is called in VS). One idea I have is to stop grouping files within the project explorer in this fashion:
+interfaces +namespaceA iread.h +headers +namespaceA read.h +source +namespaceA read.cpp +mocks +namespaceA mockread.h mockread.cpp +tests +namespaceA testread.h testread.cpp
and do this instead:
+namespaceA read.cpp read.h readi.h readmock.cpp readmock.h readtest.cpp readtest.h
This will group files associated with a particular class together in the solution explorer. Is this a good idea? How do you do things? Would be wierd to have an IRead interface in a readi.h file... Michael Feathers writes that he doesn't use the I at all but I prefer to use it... The vast majority of my interfaces have only one implementation class associated with them.
How do you organise your projects on disk?
Any other tips? Do you get headaches too?
Thanks,
Barry
Upvotes: 2
Views: 471
Reputation: 39384
Unfortunately with C++ the 'header and module' thing is not going away soon.
My tips for the source/mocks/test file problems are:
Upvotes: 2