Dealing with legacy code – Reversed Tests Pyramid

Wiktor Żołnowski

Talk: 60 minutes

Summary

Most of us – developers, deal with already written code (written few years or even decades ago), which is not understandable by no-one, and no-one knows what particular lines or functions are really doing.

Reversed tests pyramid is the way how we can clean up our legacy code (this is the proper name for code described above).

If we cannot write unit tests (this is difficult for legacy code) we start with writing end-to-end tests so that we can get feedback during refactoring.

The problem is that so often people forget that end-to-end tests are not the best way. This kind of testing takes too much time and it is very difficult to maintain. This is the reason why end-to-end tests soon or later become legacy too – because of that value of this tests decreases during time.

The other problem is we sometimes forget why we are doing refactoring and we are doing refactoring just for refactoring (without any purpose) very often. The main goal for refactoring in legacy code should be making it testable by unit tests. After that, we can take care about other important things.

During this process, which I like to call “reversing tests pyramid back”, we need to remember about removing all end-to-end tests which became duplicated by unit testing. There should be only few, most important end-to-end tests. If we really need end-to-end tests to test our software – we are doing something wrong.

Short Bio

Wiktor Żołnowski – Agile Coach, Consultant and Trainer focused on process improvements and basic technical practices like TDD, BDD, Emergent Architecture and Pair Programming. During last few years he has been participating and leading couple Agile transitions in various IT organisations. Currently he is working at Code Sprinters – Agile coaching company from Poland.