Legacy Code Challenges

You can't be agile when your code is fragile. Unfortunately, many of the essential Java applications in production today are composed of Java code that is fragile – and therefore not built for change. Complexity makes code fragile – if you make a change to fix a bug or add a feature, you're likely to break something else by accident. Lack of tests also makes code fragile, since a change that introduces a bug is less likely to be detected. To be agile you need to be able to modify code easily and safely.

The problem is that many Java applications are too fragile to maintain and enhance without heroics and fire-fighting, which is a source of real drag on the organization. People often refer to this as a legacy code problem, since much of the old code still in use was never delivered with good tests, and has deteriorated from many changes that were grafted on long after the code was first delivered. But there's also a lot of legacy code that's brand new – new code can be complex and badly tested just as much as old code.

It's useful and accurate to think of legacy code as any code without tests (see Michael Feathers in his book, Working Effectively with Legacy Code, Prentice Hall, 2005).

How do you reduce the drag or tax from your legacy code, so you can reduce the maintenance burden and free more of your team for new development? You need tests. In particular, you need a good set of unit tests. The tests make it easier to detect changes that could be regressions. And the tests serve as the foundation that allows you to improve and simplify your code to make it easier to work with.

AgitarOne JUnit Generator is the best solution available to reduce your legacy code problems. It creates JUnit tests that, even on complex and ugly code, averages 80% or greater coverage at the push of a button. On ugly code you'll get some ugly tests. On good code you'll get good tests. Either way you'll get far more thorough JUnit tests than you have ever had. You'll have a safety net of JUnit tests that flag changes and help you identify regressions. These generated tests remove the fear of changing your code.

Then with a little effort to analyze the results and improve the tests, a small portion of your team can start to improve the code – simplifying it and perhaps even refactoring key parts of it, protected by the safety net. You improve your code to reduce its complexity, making it much easier to maintain and enhance.

View a five-minute demo of AgitarOne JUnit Generator's capabilities.

The next time you are fixing a bug in some dark and dusty corner of your code, generate some JUnit tests with AgitarOne JUnit Generator before you start. After you clear that first hurdle – once you have unit tests in place for your legacy code – you can improve your code with confidence. You can also use AgitarOne Agitator's exploratory testing capabilities to identify design and implementation problems in your code. As you address these, your generated tests also get better.

View a five-minute demo of AgitarOne Agitator's exploratory testing capabilities.

Tests improve your code and better code improves your tests – that's a virtuous cycle. With AgitarOne you can drive this cycle to get code you can easily and safely modify. The result – true agility you can sustain.