Agile, unit testing, xp

Leaving the code in a better shape than I found it

Yesterday evening I read the latest blog post from Uncle Bob about how refactoring can help you find dead code in your code base. A great post, you can find it here. Apparently, Uncle Bob has a policy that says that whenever he has code up in an editor, he has to try to leave it in a better shape than he found it. I think this is a great policy and although I think I will have problems applying this principle myself I will at least try to apply a policy of leaving code I work on in a better shape than when I started….

Continue reading

design, legacy code, unit testing

Refactoring legacy code – how to get them singletons under test

A couple of weeks ago I bought the book “Working Effectively with Legacy Code” (WELC) by Michael Feathers (MF). I’m now more than halfway through this excellent book and can’t help to regret I didn’t buy this one long time ago. It is an absolutely “must have” for all programmers working with legacy code and who are struggling to get these nasty systems under test.

In a recent post I discussed how I was able to build a service layer on top of a legacy code base and successfully unit test these services using the adapter pattern. In order to create the required services we needed to try and understand the legacy code we were interfacing with. With over 1000 classes, some of them over 5000 lines long and with 0 % unit test coverage, this was very challenging indeed. This code base is practically crying for some refactoring and with this great book in my possession, I wanted to try out some of the theories. Here’s how it went…..

Continue reading

mock objects, patterns, unit testing

Unit testing services built on top of a legacy system

I wrote this article, unit testing with mock objects, a couple of years ago. The motivation behind it was to share some of my experiences from using mock objects when testing a service oriented interface built on top of a legacy backend system. Since then I have gained some more experience about this subject. The article is not updated however to reflect this increase in knowledge (time is a limited resource) . I’m publishing the original article and hope that it may be of interest to somebody out there. Even though I would change a great deal if I was to re-write the article, I still feel that using the Adapter pattern is a good aproach when it comes to testing business logic accessing a legacy backend system. Continue reading