Menu:

Delicious!

arrow Drawing with jquery

arrow Mobile applications RIP

arrow Lighthttpd tuning

arrow Kännykästä WLAN tukiasema

arrow MySQL advanced performance tips

 left_thumb_25102008-002.jpgleft_thumb_24102008-032.jpgleft_thumb_24102008-015.jpgleft_thumb_24102008-013.jpgleft_thumb_20092008.jpg 

Dezign
(4 Janv, 2007)

Why unit tests are cool

Posted on 2009-10-03 10:52:08 EEST.


It has been a while since my last posting. Quite a lot of business and lack of personal time to write. There has been more important things like finishing up studies and master thesis.

One could be thinking why write those unit tests. Especially if you have buggy free code or libraries what is the catch there. It's labourfull to make those tests. But still you are most likely to do some interesting test cases that you were not thinking while implementing your original solutions.

I call these to "grey" areas. There might be cases where your function returns nothing or null when it should return true or false. This can happen quite often with PHP. You want to make simple function but then something goes wrong when the code above your basic function behaves badly.

In fact when writing your unit test you should have very destructive mindset and write also those "should be impossible" combinations. And what should your function do when something "impossible" happens? Should it try and correct the situation?

I've come to conclusion that strict approach is the best. Depending the programming language those grey areas are best addressed with for example exceptions. And why? The programmer above immediately gets feedback that something is going wrong thus preventing further damage. So put some informative message to that exception and be defencive.

Write those unit tests!

Back