Unit Testing in ASP.NET MVC - Easy Guide for Beginners and Professional






What is Unit Testing ? 

 Unit tests are definitely becoming a need-to-have skill for developers to confirm their code does what it should for production.

 1.In real world every application comprises of many modules. For instance consider a simple E-Commerce application may comprises of Inventory Module, Customer management Module, Order module etc.

 2. Every Module is made of using more than one classes.

3. Every class exposes many functionalities in the form of functions. In Unit Testing we test these functions individually in an automated manner.

Get Easiest & Simplest idea about ASP.NET MVC

What are some general guidelines for Unit Testing? 

 Make sure you unit tests tests what needs to be unit tested…and nothing more.

 If you have a simple POCO (Plain Old CLR Object) with a list of properties with no implementation or business rules behind it, I’m guessing you don’t need to test it.

Your code should be unit testable. If it’s not, you may need to rethink your design. 

Sometimes, it’s a good idea to write your unit test first. That way, you get a clear understanding and perspective of how developers will interact with your code. If it’s not clear in your unit test, what makes you think that developers will understand it in production?

 You really don’t need to mock everything

 Some users mock the heck out of everything because they can. For example, your business objects. No mocking is necessary. You can new one up just to see if code is structurally sound and passes a specific business requirement.

If a business routine or rule is really complex, write unit tests around it (or take a hammer to it )

Confirm the nature of the routine by writing unit tests. If it’s really complicated and it’s a long method, “break” it into manageable pieces of code. Breaking this code smell into manageable chunks of code will accomplish two things: smaller, testable routines for unit testing and a better understanding of the code since it’s refactored.

Also Read:

Comments

Popular posts from this blog

Top25 ASP.NET Interview Questions - FAQ | Crack the Interview Easily

State Management in ASP.Net:

The Future of .NET Developement