It’s usually good practice to have automated unit tests while developing your code. Doing so helps you find bugs early in the development cycle and saves you time in the long run. These tests can be run by the developer multiple times to verify the behavior of a particular unit of code for different sets of input.
Unit tests essentially check the behavior of a particular unit of the code or the function and are written by the developers who are implementing the functionalities.
We test the behavior of a function before it becomes part of the whole system and goes into production by writing a piece of code to test this behavior under different conditions. Usually, a function gets tested in isolation with the other functions of the system under test (SUT).
In .NET, there are two options to write Unit Tests:
1. Using MS Test
2. Using NUnit
3. Using XUnit
In the article "Getting started with .NET unit testing using NUnit", you can learn to start Unit testing of C# classes using NUnit. This article will walk through:
- Creating the system under test
- Setting up NUnit
- Creating the Test project
- Creating Test classes and methods
- Different options for running the tests
- Understanding TestFixtures and TestTearDown
- Working with Ignore test