How to Test Coupled Code: Seams

It is very likely that sooner or later we will have to face code that has two characteristics:

  • Untested code
  • Highly coupled code

What should we do first: the test, or the refactoring to be able to test better? The egg or the hen? We already know why not to use static, but it may be that "our self from a year ago," or even that project we've joined, makes use of these types of practices. It's possible that even that project has a large base of untested code. But this shouldn't be a problem for us; we have watched the CodelyTV videos and we are trained for this and more :D In today's video, we will see a practical application of the concept of seam. This concept is related to a technique that can be useful when navigating through code that has the two aforementioned characteristics (coupled and untested). This technique will help us modify our code as little as possible in order to make it easier to test. The procedure will be as follows:

  1. Apply the technique we will see in the video (open a seam)
  2. Develop our test focused on the component we want to test while ignoring the collaborating classes it is coupled with
  3. Deeply refactor, now with the peace of mind of the test we have been able to implement

As I mention in the video, I discovered this technique at a Barcelona Software Craftsmanship meetup thanks to Manuel Rivero. If I’m not mistaken, it was cited from the book "Working Effectively with Legacy Code". I would also like to mention the original post on which this video is based: Testing legacy: Hard-wired dependencies (by Sandro Mancuso). Finally, remember that these types of couplings can be easily identified if we know how to listen to our tests, that mysterious ship we talked about some time ago :)

Pay according to your needs

lite (only monthly)

19 €
per month
  • Access to a subset of courses to lay the foundation for maintainable, scalable, and testable code
  • Company invoice
Popular

standard

24,92 €
Save 121
Annual payment of 299
per month
  • Full course catalog
  • Design and architecture challenges
  • Highlighted solutions videos for challenges
  • Receive job offers verified by Codely
  • Company invoice

premium

41,58 €
Save 89
Annual payment of 499
per month
  • Everything above
  • More benefits coming soon

We won’t increase the price while your subscription is active