Posted by: ahmedashfaque | May 4, 2015

Unit testing for software products

Testing during software development is very important as it will ensure a defect free software product. A defective software product can lead to many problems to the users as well as the software product vendor as well. Most people understand problems of using a software product.

So how to ensure a defect free software product? Software product should be tested from the very beginning when the software product starts getting developed to the very end when the software product is ready to be shipped. Any defect found during this entire spaan of time when the software product is under development, should be fixed immediately.

To ensure that defects are not getting injected in the software product, testing should start even before developers start writing their source code. In object oriented programming, when a developer writes a class, a test case should be written to test this class and its methods. This level of testing is known as unit testing as this testing is done at a unit (class) of source code. Only when all unit testing is done and all these tests pass successfully, a developer should integrate this piece of source code with the software build where all fresh source code is integrated.

A unit test should check the business logic implemented in methods inside the classes. A method does some computation and provides some output based on the inputs it receives either from the user or from any other software program unit. In unit tests, input values from boundary conditions should be provided and output values should be checked to verify if the method is doing right computation. For example suppose a method is created to compute sum of 2 integers and these integers should have values within the range of 1 to 100. Then in unit testing you should create test cases which will provide inputs in the range of less than 1 (e.g. -1) and more than 100 (e.g. 101). These 2 test cases will give negative results (the tests will fail) when they are run against the method which you are testing. So these test cases are known as negative test cases.

You should also create a test case which will provide values within the range (e.g. 50). This test case should pass as it will meet the criteria for business logic. This test case is known as positive test case. When you run this test case and if this test case passes then you business logic implemented in your method is fine. If this test case fails then your business logic implementation is wrong and you need to fix it.

You can write your test case manually. But writing and maintaining manual test cases is a laborious task. Now a days good tools are available which help you in creating, maintaining and automatically running test cases. When you maintain your source code later (refactoring for example) then you can again use the suite of test cases written to do regression testing.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: