TDD, Unit Tests and Mocking

TDD: Test driven development is a development approach where direction of development is driven by tests. As the name suggests, in TDD, first piece of code to written is test case, then actual piece of code.

Unit Test: Unit test is a programming method to writes test cases for your application. Unit testing is used to break down the functionality of your program to a discrete testable piece. Unit test are also important to create a code coverage report. Thru Unit test, the code and logic written becomes testable and thus reliable.

In Visual studio, Test Projects and Unit Tests can be generated by few clicks or can also be manually.

Unit testing has the greatest effect on the quality of your code. Unit test are also useful in finding code breaking changes.


The AAA Syntax (Arrange, Act, Assert)

Mocking: Mocking is literally faking any object, function or context. Mocking is a concept where objects are faked when it is not possible to access (or generate) in testing framework.

When (or what) to mock: These are scenarios where mocking is frequent.

  1. Static objects
  2. HTTP context
  3. Databases (sometimes)

Mocking Libraries: There are different mocking libraries available, using which mocking can be done easily. Examples: Moq

Author: Rupesh

Hi! I'm Rupesh, technophile and funophile. I'm an Application Developer, Solution Architect and IT-Consultant. I am a Microsoft certified Professional (MCP,MCSD,MCSA,MCSE). My hobby includes reading, writing, tennis, bollywood and cricket

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