Thursday, October 03, 2013

xUnit : Low Cost/Commitment Unit Testing

I have been having love/hate relationship with Unit Testing so far. I understand the need and rationale behind it and often times I even enjoy doing it and makes programming more fun. However, when the tests has hit certain large  numbers and you accumulated significant cases where it just hard, if not impossible, to test (despite decoupling the code heavily and usage of patterns in high-dose), unit tests becomes a chore and annoying burden to maintain. You start to question yourself it's worth the trouble and should you just going forward without TDD.

I find the test framework that I use is a significant factor whether I keep unit-test the code. Having found xUnit sometime ago, I can now say again unit testing is functional, useful and fun again. Unit tests is support/driving activity of the main activity (coding), so the simplest possible support code/framework is the way to go.  xUnit has minimal "accessories" which make writing test code quick and straightforward. So far, it fits my need of unit test framework. For example, it get rid of Setup and Teardown and use very minimal set of attributes.

One important thing, psychologically for me, of having simple unit test framework is it makes my attachment to my unit tests relatively low. This means I can throw away, rewrite, change my unit test anytime and anyway I want with very minimal guilt. I can throw away large number of any unit tests that no longer serve any purpose and start over with the tests progressively. I can do architectural level changes with more freedom without unit test maintenance becoming too much of a burden. My focus now back to the main logic of program with unit test to support it.

Of course, at some level, unit test framework can be very personal choice like choices of your favorite text editors or OS. Personally, I like xUnit for my (.Net) testing framework. If you have been throwing unit testing from your development arsenal lately, you might want to try xUnit and see if it can interest you to get back to unit testing your code again.

No comments: