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.
- Static objects
- HTTP context
- Databases (sometimes)
Mocking Libraries: There are different mocking libraries available, using which mocking can be done easily. Examples: Moq