views:

209

answers:

2

I work on a project that was just told we had to incorporate Parasoft C++ unit testing tool into any code changes going forward. The problem I face is that we have methods with very small changes and now it seems we are forced to unit test the whole method. Many of these methods are hundreds or thousands of lines of code. I know for certain that if I have to test the methods entirely then we will run into fixing old issues such as null pointer checks and our budget and manpower can't handle these fixes.

Does anyone know if parasoft allows you to test small portions of a method? or if another unit testing framework would work better.

+3  A: 

Implement the small change you are making in a new method, test that. Then change the original to call the new method.

You will be testing the change and gotten a little refactor to better code.

Lou Franco
sounds like a good last resort work around, I'll keep it in mind. Most of the changes would not make sense to make new methods but might be a good opportunity to refactor more then just the changes.
Andrew Jahn
A: 

No unit testing framework allows you to just test portions of a method.

One ugly suggestion is to use #include to include small chunks of code directly into methods, with the same #include used to include that code into a testing method that sets up variables used by that code.

I recommend Michael Feather's book Working Effectively with Legacy Code for advice on how to add testing to a large code base. It's also available online at Safari.

Andy Dent