I have been participating in the unit testing discussion for quite some time and does know that Unit testing is considered as one of tools which can increase the quality of the code which in turn improves the quality of the product, but still lot many people shy away from writing the unit tests. Couple of year’s back I had asked couple of experienced developers as why they don’t always write unit tests, and I got some of below interesting answers,
- Clients do not pay for Unit tests since unit tests are never part of agreed deliverable.
When client hires a developer to write some functionality, rates are agreed and paid for the functionality developed by the developer. Clients in most of the cases do not really bother as how developers write their code, what type of art they use to write and develop the functionality , all clients requires is working functionality. I would say it’s fair enough expectation from client. However when IT is your long term business or your business depends heavily on IT than probably you don’t want to skip unit tests. I suggest keep an on this blog for more my thoughts in coming posts or probably you can ask some veteran who is in business of coding or in business of developing products from scratch. IT is all about code and nothing else.
2. Unit tests do not assure the quality of your code completely, we still need QA to test the code or functionality.
This is another good reason for getting rid of unit tests. There are certain types of tests which most unit tester don’t cover for various reasons. Functional Testing, System testing etc. etc. are some of the types which are not covered by current existing practices of unit testing. However technically speaking, I believe unit tests can be extended to do Functional Testing, System Testing or Performance Testing. However if you are writing unit tests, you should probably be able to cut down the QA cycle by at least 30 to 40% , if you are not able to achieve even close to 20% , then probably your unit tests are not real unit tests.
3. There isn’t enough time to write unit tests.
This is another very good reason for not writing unit tests. Probably there isn’t time to write tests because time is just not accounted for in Project Management Plan. Most Project Manager I have spoken or seen, never included or tracked the activities of Unit tests. So even if you want to write it, probably you will not have time to write it since it’s not there in project schedule.
4. Its pain to write tests when requirements are changing.
This is fairly true reason. Requirements keeps on changing and with change, it adds over heads to all teams. It’s the way life works in IT. The thumb rule of IT is whenever requirements stops, growth stops. Changing requirements is the only way to see that company is making an attempt to grow at least for those whose core business is IT.
5. It’s much appreciated to develop the functionality and toss the code to QA.
I personally believe in having rock star developers and superstar testers in a team. So I would appreciate if developers can focus on developing functionality and testers focus on unit testing that code base. However I also believe that developers needs to toss the bare minimum working code to QA that does what it’s supposed to do. Things that code is not supposed to do , things that makes code to do what it’s not supposed to do, things what code does when it’s not supposed to do etc. etc. can be taken care by testers at the code development phase itself. However most unit test guru’s out their will not favor this approach. They expect developers to test their code for its accuracy by exercising both depth and breadth of code. They believe if I have written the code, only I knows its intent best, so only I can test it in best way. Probably I believe this thought process is the one which killed unit testing in the first place.
6. We do not have robust libraries out there still which can test every bit and pieces of the code.
One of things which I always wondered what if I am using the JDK for developing my applications, do oracle provide me some help as how to unit test their classes or probably if I am using .net framework, is there any guidance coming from Microsoft as how to unit test their .net framework classes ?. This may sound like naïve thoughts, but as we get into the lower level details, it’s just more than calling the methods or checking their return values. In short there is not enough material available to get best out of unit tests.
7. They do not test the end to end integration of systems.
Unit testing was born to test smallest bit of code. Integration testing or system testing involves lot of dependency, and also lot of other work which extends beyond the developer’s desk at times. As I said earlier, unit tests can be extended to do integration tests, system tests etc. etc. I believe in extending unit tests as it will save your lot of downstream QA effort. However it needs to planned and executed properly.Probably its time for unit system tests and unit integration tests.
8. In few cases technical complexity of the code restricts the testability of the feature at the code level.
Well this statement is also true, however with growth of agile practices, lot of people believe that if your code cannot be tested, then probably it’s a bad code and should not get into production. There might be few exceptions to this like using private methods for security purposes etc.
9. There aren’t enough people to who has knowledge or skills of doing unit testing.
Skilled resources are always hard to find. However I believe that existing skillsets of QA can be leveraged to do Unit testing. Anyone who prepares the script should be able to write Unit tests. It might take time to learn the trick of the trade, but they should be able to do it.
10. Unit testing is for Young and Rookie Developers.
I had seen lot many young people (1 years to 5 years development experiences) doing unit testing and experienced ones writing the code base. I don’t know as why only young developers are made to write unit tests and experienced one shy away from it. Probably they don’t want to get associated with anything which has word “test” associated with it.
I am sure there could be many more reasons in addition to above which I might not be thought about now. But I still feel Unit testing is one core skills which can improve the quality of the product with minimal investment. It’s just that there is not enough guidance and awareness among the masses and probably that’s reason we come up with intelligent ways to avoid it.
Comments are closed here.