dimanche 26 octobre 2014

Growing Object Oriented Software guided by tests

I'm reading this book these days and I'm so impressed on how it provides answers to my latests questions.

The main goal of the book is to provide clues to deal with dependencies as you build software using TDD technique.

Often, when you look at TDD examples, you see simple problem katas, without GUI or a database or any other stuffs that are so painful to deal with. That's OK, because these external systems do not help you to solve the problem, they're just a mean to provide data or to present data to the user. Data computation is our core business as programmers.

On my current project at work, we have a huge amount of dependancies as we are calling about twenty web services for retrieving and modifying data. And we are to add a database connection. We do not abstracted service call correctly. We wrote tests, but mainly integration tests that are unusable today for the most part as we are facing performance issues.

So here we are, passing dependancies all over the place and dealing with complicated DTO. I'm working on it and reading this book is comforting me and guide me in mocking practices. As you may know, mocking in tests is far from being easy.

These books confirmed these points to me :

  • I should mock what I own. This way, I want have to change all my mocks when the signature of the web services I call change.
  • I should consider passing lots of dependancies in a class constructor is a smell, a sign that I have to break down stuff.
  • Loggers represent the most malign dependency. Even them have to be abstracted behind constructs I own.

This book is a must read if you are interested or already practicing in TDD. My only concern is that you have to be in good shape to read example code. They're written in Java, and use jMock a lot which is not the most popular these days, as far as I know.