Please enable Javascript to correctly display the contents on Dot Net Tricks!

What is Unit Testing and Why to use it?

  Author : Shailendra Chauhan
Posted On : 15 Jun 2015
Total Views : 10,588   
Updated On : 20 Jul 2015
 

Unit testing is a way to test each piece of your code which is called as unit. The idea behind the unit testing is to ensure the quality of each smaller unit. It verify the functional behavior of each unit in response to correct and incorrect cases of input data and verify any assumptions made by the code. Unit test cases are usually written by the developer who has written that code unit.

Developers can also use test frameworks as per their programming languages or frameworks of code, to make writing and running unit tests easier.

For example, .NET developers use NUnit, XUnit and third-party mock-object libraries such as Rhino mocks, Type mocks or NMock to write and running unit tests.

Visual Studio Test Explorer

Visual Studio Test Explorer is designed for developers to run your unit tests and view their results in Visual Studio. It can be used to run tests written in .NET languages (C#, VB.NET) and other programming languages like javascript or JS framework like AngularJS with the help of Visual Studio Extension.

You can download these third party testing extensions from Visual Studio gallery.

Test Explorer views display all of your tests - passed, failed, not run yet, or skipped. You can also do filter or search for a specific test in Test Explorer view at the global level or by selecting one of the pre-defined filters.

Why Unit Testing?

Unit tests reduce number of bugs, provide accurate documentation, and improve design. There are following reasons to choose unit testing.

  1. Allow you to make big changes into code quickly since you know it's tests are working as expected and when you make the changes you need to write and run tests again to get it work.

  2. Reduce the number of bugs in production code.

  3. Help you to understand the design of the code since to write tests you need to outline all the conditions with respect to your code and what outputs you are expecting from the code.

  4. Allow refactoring of code at any time without fear of breaking existing code. In this way it make the coding process more agile.

  5. Ensure functional behavior of your code since all the tests have been passed.

What do you think?

I hope you will enjoy Unit Testing for writing a better code. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.



Free Interview Books
 
COMMENTS (0)
11 MAR
ASP.NET MVC with Angular2 Development (Online)

09:00 PM - 11:00 PM IST( TUS, THR, SAT)

Know More
6 MAR
Master Class Fast Track MVC 5 with Angular2 Development (Online)

10:30 AM -03:30 PM IST (Fast Track)

Know More
6 MAR
Angular 2 Master Class Fast Track Online Development Training (Online)

10:30 AM- 01:30 PM IST

Know More
27 FEB
ASP.NET MVC with Angular2 Development (Online)

07:00 AM - 09:00 AM IST( MON, WED, FRI)

Know More
25 FEB
ASP.NET MVC with Angular2 Development (Classroom)

05:00 PM-06:30 PM

Know More
25 FEB
Xamarin Forms : Build Cross-platform Apps (Classroom)

3:00 PM-4:30 PM IST

Know More
25 FEB
ASP.NET MVC with Angular2 Development (Classroom)

3:00 PM-4:30 PM

Know More
14 FEB
.NET Development (Classroom)

11:00 AM-12:00 PM

31 JAN
ASP.NET MVC with Angular2 Development (Online)

07:00 AM-09:00 AM IST(Tuesday & Thursday)

30 JAN
NODEJS & MEAN Stack 2.x Development (Online)

09:00 PM-11:00 PM IST( MON, WED, FRI)

15 JAN
PPC Marketing (Classroom)

04:00 PM-05:30 PM

10 JAN
ASP.NET MVC with AngularJS Development (Online)

09:00 PM-11:00 PM IST on (TUE, THRU,SAT)

31 DEC
ASP.NET MVC with AngularJS Development (Classroom)

09:30 AM-11:00 AM

5 NOV
ASP.NET MVC with AngularJS Development (Classroom)

08:00 AM-09:30 AM

BROWSE BY CATEGORY
 
 
LIKE US ON FACEBOOK
 

Professional Speaks

+