Unit Testing : Did you test the code ?

As a developer, we all love doing coding , love to make something magical , something that makes people say a word amazingly , ‘WOW’ ! We love our code to be working perfectly in production, in front of our clients and want that to be unique piece of art of ours. Yeah, that’s good.  We all know and always keep that in mind very STRONGLY , to develop something there are different steps like requirement analysis, design, core development bla bla.

BUT the fact is , how many of us really , really follow these steps ? Many of us prefer the shortcut way to do things and like to deploy the project as soon as possible , and to do that, in most cases we always ignore or overlook a very IMPORTANT step , that is unit testing and debugging. How many of us can avaoid thinking “AH ! Unit testing ! Debugging ! What’s the need of these ? You see, the project has already been developed .”

Whoops ! That’s the biggest mistake we do thinking this way. Cause, unit testing and debugging is the vital part undoubtedly. Why ? Okay , let it be explained a bit more with real life example.

When we want to buy  shoe in the market for us, we always prefer something having the following criteria

  • Good looking ( UI )
  • Comfortable ( UX )
  • And last and most importantly, defect free ( in case of software, it is ‘bugless’)

Yeah, we want our desirable product , even if it is shoe, to be defect free.  We don’t want even a single tiny leak even in the bottom of it. And same thing goes for software. When a customer or client goes to buy something , he expect it to be bug free . Your software even with super cool UI/UX  can lose its appeal to the customer for a single bug. On the other side, another software with simple plain UI can be the winner in the competition. And obviously , you don’t want that.

That makes the need for testing for a software . And unit testing is a part of it. It is a stage/phase that comes after the development. In this stage, each and every unit/component of software is tested to ensure that the corresponding unit is working as expected.  It is done with some sample data making them passed through the unit/component and checking if the desirable output is obtained.

If any test is not passed, you will find an error or warning or notice with the exact line nubmer where this occurs, and depending on the description of that error/warning/notice, you can make correction needed to your code and run your test again. This is the basic concept of unit testing.

Some ponints can be huge benifits of unit testing :

  1.  Developing , improving and integrating different features in a software is a common scenario . Doing these tasks becomes so easy . Cause, modifying code can make bug , but because of unit testing , the bug can be easily tracked and solved without hassles.
  2. Since , code must be written in clean in organized way , the code becomes reusable.
  3. Debugging becomes easy, very easy.
  4. Since all codes are passed through tests with success, code becomes reliable.
  5. Total development time incluing releasing the final version becomes much more shorter.

There are different frameworks out there for different programming language to perform unit testing . You can chose one depending on your taste and what language your software has been developed with. Some remarkable names  that can mentioned are

  1. PHPUnit : an unit testing framework for php
  2. JUnit : it is for java
  3. Unittest : for python
  4. QUnit : for javascript

But these are not all. There are many more. You can find a full list here and chose any of them.

There’s a lot of resource out there to learn unit testing in depth and know it more. An article on it in tutsplus can be mentioned in this case.

Besides , there’s another nice tutorial in tutorialspoint on it that demonstrates every bit of it step by step.

Don’t have much time now and want to learn at a glance ? You can go through this one for that.

Enough for today. Hope , this will be helpful for you to get a good start on making unit testing in your code. Happy coding . 🙂

2 responses

  1. I’m very happy to find this page. I need to to thank you for your time due to this fantastic read!! I definitely enjoyed every part of it and I have you book marked to see new stuff on your web site.

Leave a Reply

Your email address will not be published. Required fields are marked *