
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Unit Testing for C# Code
Unit testing is a key for C# code since it can help in maintaining code in the development process. It lets you know about the problems in the development cycle.
With Unit Testing, you can make the code reliable and reusable.
One of the fundamental principles of adopting unit testing is to follow a TDD (Test Driven Development) approach where we have to write tests case first, and then write the simple code that will make the test pass
For Unit testing, you need to work with Microsoft Testing tools, which is what we call MS Unit Test.
To create a Unit Test, go to Solution Explorer, right-click, go to New and click “New Project”.
Now select “Unit Test Project” −

Set a name for the Test and click Ok.
New Unit Test project is created.
Now right click on the new unit test and add the following reference −
Microsoft.VisualStudio.QualityTools.UnitTestFramework
- Related Articles
- Unit Testing Tutorial for Beginners (Concepts, Types, Tools)
- Difference between Unit Testing and Integration Testing
- Difference between Unit Testing and Sandwich Testing
- Difference between Unit Testing and System Testing
- What is Python Unit Testing?
- Unit Testing in Python using Unittest
- Unit Testing using Unittest in Python
- Unit Testing in Python Program using Unittest
- Unit Testing Challenges with Modular JavaScript Patterns
- How to perform Automated Unit Testing with JavaScript?
- How to verify an exception that has been thrown in unit testing C#?
- Optimization Tips for C# Code
- C program for testing the character type
- Testing for Asperger’s Syndrome
- C++ code for calculation of a physics experiment
