Reversed Test Pyramid - Testing and dealing with Legacy Code
-
Easy
-
Most of us – developers, deal with already written code (written few years or even decades ago), which is not understandable by anyone, 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 now we can have some feedback during refactoring. The problem is that so often people forget that end-to-end tests are not the best way to test their software. 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 the time. The other problem is that we sometimes forget why we are doing this refactoring? Often we are doing refactoring just for refactoring (without any purpose). The main goal for refactoring in legacy code should be making it testable by unit tests. Only after that, we can take care of 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 a few, most important end-to-end tests.
Presentation
Video