Pages

Friday, January 22, 2016

Unit Testing

Introduction

In the programming world, we often come across a word known as "Unit Testing". Many of us may or may not know what exactly it is. So in this post, I will share some of the information about Unit Testing with you all.

Few questions and their answers which are really important and must to know about "Unit Testing" are: 

What is Unit Testing?

Units are the smallest building blocks of software system. 

Unit testing takes place in the development environment and is the process of validating small building blocks of a software system before testing the system as a whole. 

Unit testing focuses on testing individual units of the software to ensure that those units are functioning the way they are supposed to do before integrating multiple units into modules.

Who does Unit Testing? 


When following a structural unit testing approach, also known as white-box testing, both developer and unit tester are the same.


When following a functional unit testing process, also known as black-box testing, developer and unit tester could be different people.


Why is Unit Testing Required? 


Unit testing is performed to improve the overall quality of the software written by developers in Construction Stage of the SDLC.

Since the unit testing is performed during the Construction Stage, developers can find defects earlier in the SDLC and fix them before system testing.



Above are the overall details about "What", "Who" and "Why" of Unit Testing. Let's see what are the advantages of "Unit Testing".

Advantage of Unit Testing

There are numerous benefits of performing unit testing:

Faster Development – When you write unit tests you'll spend less time debugging, and you'll have more confidence that changes to your code actually work. This confidence allows you to get more aggressive about refactoring code and adding new features. Without tests, it’s easy to become paranoid about refactoring or adding new features because you don't know what might break as a result.

Faster Debugging – Without unit testing, the time it takes to debug or resolve a functional test that may have failed can take a long time to track down. With unit testing however, the scope of the test is kept to a minimum, and the point at which a failure may be triggered can be isolated faster.

Better Design and Documentation – Writing unit tests forces developers into thinking how their code is going to be used and has generally resulted in better design and even better documentation. A comprehensive test suite can also help document the implicit behavior of the methods exposed in the classes, providing another mechanism for developers to find out more about the intended design of the class.

Better Feedback Mechanism – When all unit tests for a system are run as a whole, the state of the system as a whole can be measured. Unit tests also provide other developers with an instant mechanism of evaluating whether other parts of the code base are meeting their requirements or are still under development. Changes in test environments may sometimes cause problems with the code base, and continuous reporting of the unit test suites as a whole can help to indicate the state of the test environment.

Good Regression Testing Tool – A comprehensive unit test suite enables major refactoring and restructuring of the code base to be completed with greater confidence. As long as unit tests continue to pass, developers can be confident that their changes to the code did not have a negative impact on the functionality of the application as a whole.

Reduce Future Cost – Many studies have proved that it costs significantly more money to fix a bug found later in its release than earlier in its development. A good unit test suite will uncover basic bugs early on in the development cycle, reducing the potential of bugs surfacing later and reducing cost of future maintenance.



So, what all tools are available for different set of technologies to provide "Unit Testing" solutions?

Unit Testing Tooling Options

No single tool is likely to provide Unit Testing solutions for all the roadmaps//technologies and all types of units. The following list are popular Unit Testing tools for different types of technologies.

.NET
• Unit testing frameworks: NUnit, MSTest, xUnit, MBUnit
• Isolation frameworks: Microsoft Fakes, Moq, NUnit. Mocks
• Code Coverage frameworks: MSTest, OpenCover, dotCover, NCover

SQL Server
• Unit testing frameworks: Microsoft DB Test, tSQLt, redgate SQL Test

JavaScript
• Unit testing frameworks: Quit, Jasmine
• Test Runner frameworks: Karma, Chutzpah test running (Visual studio integrated test runner)

JAVA
• Unit testing frameworks: JUnit

PHP
• Unit testing frameworks: PHPUnit


Conclusion


In this post, we learnt and touched main content, information and questions/answers about "Unit Testing". I hope this post will help!

No comments:

Post a Comment