Wednesday, May 30, 2007

Writing Code for Easy Testing

As a developer, what kind of code are going to write? A code that easy readable? A code that is easy maintainable ? Well, I think, writing a code that is easy for testing come first =)

Actually a code that is easy for testing also meaning that piece of code is easy to read, easy to maintain. Recently encounter such situation...

[Big] a very big service object
[Serv] a service object
[Abstr] a abstract object
[Conc] family of [Abstr], meaning [Conc] can use all feature in [Abstr]

To fulfill a hug task, [Big] -> [Serv] -> [Abstr] -> [Conc]

Not all methods in [Serv] are exposed to [Big] , meaning [Serv] will do itself in it's context, but it depends something from [Big].

[Conc] and [Abstr] is really a terrible "couple". Some methods in [Conc] will call methods in [Abstr], even worse that [Abstr] might call back to [Conc] in the same method!

So, when going to test a very very small task. Need to understand all this 4 Classes! Should it be just need to understand [Conc] is enough? Today, thinking of testing that very very small task, so need to write a new [NewConc] that based on [Conc], but found out that this 4 Classes are very dependable, So give up. Yiak.

Come out a plan to Revamp whole things ? Well... All because of that [Big] thing. Which is also used by others NOT similar [Serv] object. So give up also.

So, write a code that is really really easy to test is Top priority. =)

No comments: