Repairing Legacy Code - Automatically
Many Projects already use automated regression testing. Unfortunately we cannot rely on this in situations that need them most, for maintaining foreign (untested) legacy code. Here I do not only wish for automated regression tests, I also wish for automated test generators. Why does such a tool not exist?
I think that many developers justify this with the fact that code is too complex to clean it automatically. Actually complexity is the main impediment for automation - automation needs simple stupid tasks.
However - test writing is a kind of simple stupid:
- I choose a method to test
- I determine the state before this method that could influence the method (pre-state)
- I determine the state after this method that was written by the method (post-state)
- I combine the call of the method with different pre-/post-state pairs, setting up the pre-state and checking the post-state after calling the method
Yet it’s not easy:
- the programming language can inhibit you (e.g. information hiding can deny the access to the full state you need)
- the mere size of the pre-/post-states is often too large to analyze (legacy code in particular tends to depend on large states)
Both of these problems are typical human developer problems. Scaling and getting access to internal state is simple for an automatic tool. I would have guessed that such a tool already exists. The simple search for a tool generating or recording tests, or at least for a tool serializing program state brought no results. So I decided to create my own prototype.
My solution for the automatic test generator is testrecorder. I will post my progress on this subject in this blog.