Friday, November 03, 2006

Unit Testing is a Dev Task

These days, I find myself playing unit test evangelist to my peers a fair bit . Someone will suggest an argument why unit testing isn't feasible and I'll spout off counter-arguments that I've either learnt from wise people, or made up myself (generally the former).

And if (when!) my peers eventually concede my point (to get me to shut up) - they usually ask one more question:

"But will our project manager let us introduce unit testing in this project?"

And to some people this can be tricky. But it really depends or your point of view.

It's safe to assume that most Project Managers would expect you to deliver working code. Features that are sent to QA that break if you insert really bad data might be OK in the scheme of things, but if you send in features that you don't even know work, I'd say there would be some questions asked.

So that means that some testing is expected of developers - its just not usually explicitly stated, or if it is then it would be rare for the method of said testing to decreed.

Lets think about how development without a suit of repeatable tests usually goes:

Lets say you need to add feature X to your application, once X is implemented, how do you check that it works?

Perhaps you can run up the app, click a few buttons and eyeball the results. And sure, that can work, especially if the results are easily visualised. But what about when the feature X is altered or we introduce feature Y?

Do you do the same "test" (need to know that X still works), plus check for feature Y? Again, probably- it's definitely how I used to code. Sometimes, if I was feeling rushed or confident I wouldn't even test that feature Y didn't break feature X.

I would suggest, then, that most development tasks do in fact require some form of unit test - its just unfortunate that the bulk of these tests are unrepeatable and are never thought of again once a feature is complete.

I think moving one step further, it wouldn't be a whole lot of effort to formalise those adhoc tests into a suite of repeatable, automated tests that can be run for every check-in, nightly build or release to ensure that intent matches reality.

So, from my view, the question "But will our project manager let us introduce unit testing in this project?" can be countered with another question-

"Why do you have to ask your project manager how you should develop your application?".

0 comments:

Post a Comment