There is a legacy project full of C++ code. As a MFC GUI project, it contains lots of businesses logic out of control and beyond average level programmer to understand. To work on such GUI project, is there common techniques to add test cases/harnesses?
To problem with this projects is that you don't want to change the code without adding unit tests, but you usually can't and unit tests without changing the code.
If your project is like a typical legacy project, than you have large classes with lot of really long functions, without a clear role.
My strategy is the following:
- Try to identify the roles of a huge class (usually there is a dozen).
- Try spliting up the class alongside with these roles. Start with the simplest. Try changing as little code as possible, an mainly just move functions to the new classes.
- Each time a chunk is done, test manually.
- If you managed to split down a smaller class add unit tests, and continue with the next.
This is a really long and tireing process, and there are no silver bulets. I usually revert my changes a lot and try again with a differen approach. And manual testing is really important. The best is if you have someone who used this software a lot and can check if it really works the way it did before.
Good luck with this!
For legacy GUI applications you would benefit two ways:
Business logic track: ask sb with business knowledge for descriptive info and write UI end-to-end automated tests. You get a good test suite for regression.
Code contemplation track: if I were to write unit tests for legacy code I would do it only either for refactored or debugged code. IMHO there is no much use unit testing legacy code just to obtain regression tests set. This is why