I have a bit of a challenge and I am not sure how to approach this.
We have a very very large project (that is about 5 years old).
The code base is HUGE so a full refactor is out of the question.
What we will be doing is refactoring bits of code as we use those parts (this is backend code, which we will be using on a frontend system)
The existing code has got zero abstraction, and we want to build unit tests for it. We use the RhinoMock framework and the call from my superiors are that we need to add explicit interfaces to the code, thereby abstracting it so that we can mock the objects in RhinoMock.
I have one broader and one narrower question:
1) Is an explicit interface the best option? Or should I suggest some other technique…
2) Can anyone suggest a high-level approach to this type of code refactoring? I’ve never been in a position where I have had to add explicit interfaces to existing code. (The legacy code is Managed C++ by the way)
Thanks in advance for your answers. Also, if this question is in the wrong place or too broad, I do apologize.
3
This is one thing that annoys me about unit test frameworks – you have to change the way you code, just so you can use the unit test framework.
There are others – cppunit for example does not require interfaces inserted everywhere which, for a legacy codebase in C++, might be a better solution.
The other alternative is to split chunks of code away from the massive codebase and reimplement them as separate projects, then refactor those in isolation.
Of course, you could just say unit testing a legacy codebase is too hard,and you should spend your efforts on automated integration testing instead. That’s the way testing used to be done, and still should be used heavily even with unit-test-enabled codebases.
2