Have unit test generators helped you when working with legacy code?
- by Duncan Bayne
I am looking at a small (~70kLOC including generated) C# (.NET 4.0, some Silverlight) code-base that has very low test coverage. The code itself works in that it has passed user acceptance testing, but it is brittle and in some areas not very well factored. I would like to add solid unit test coverage around the legacy code using the usual suspects (NMock, NUnit, StatLight for the Silverlight bits).
My normal approach is to start working through the project, unit testing & refactoring, until I am satisfied with the state of the code. I've done this many times in the past, and it's worked well.
However, this time I'm thinking of using a test generator (in particular Pex) to create the test framework, then manually fleshing it out.
My question is: have you used unit test generators in the past when commencing work on a legacy codebase, and if so, would you recommend them?
My fear is that the generated tests will miss the semantic nuances of the code-base, leading to the dreaded situation of having tests for the sake of the coverage metric, rather than tests which clearly express the intended behaviour in code.