Hello, my name is Gerald. In these lessons, you will learn how to perform unit testing in Visual Studio, we will be using the MS Test framework that is included by default with Visual Studio. In this lesson, I will show you how to add a unit test project and write your first unit test. Let's take a look at our code first. Before we add some unit tests. Here in Visual Studio I have a class library opened with some extension methods for C#. We're going to test the integer extensions class and specifically the is even function. This is a C# extension method that tests the evenness of an integer, and it will return a true or false value depending on if the integer is even. So now we've learned the code, let's add a unit test project. To add a unit test project, move to your Solution Explorer, right click on your solution node and then select add, new project. So now we have the new Project Wizard screen. We're gonna search for unit test templates. Here what you may see different types of unit tests. We can see X unit test project using the X unit framework. We have a MS Test project for .Net Core and the unit test project for .Net Framework. We're gonna select the unit test project for the .Net Framework. Now we'll give our unit test project a name, I will call this unit tests. And then I will click create to add it to our solution. You can see here Visual Studio opened the first default file. I'm gonna close all these, we can look at the Solution Explorer. You can see in our Solution Explorer here, we now have two projects. We have our original class library, and a new unit test project. So before we can write unit tests, we need to reference the code that we're going to be testing. So we need to add a reference to the unit test project by right clicking on the references node and selecting add reference. This will open the Reference Manager and we are going to reference a project within our solution. Here it is the extension library. So I will check that and click okay. This will add a reference to our unit tests for the extension library project. So we can use that code. So now we have a reference added and we are ready to write unit tests. By default Visual Studio adds an example unit test class. Let's open that. First I'm going to rename our class and our test method so it lines up with the class and test method that we're going to be unit testing which is the integer extensions class and the is even function. So I'm gonna rename both of these so they line up correctly. So I've renamed the test class and the test method to line up with the code we're testing. The next important thing to take note of are these attributes on our class and their method. These attributes tell Visual Studio that these are not regular code but these are test classes and they will be picked up in the test runner and ran as unit tests. So every unit test we write will be decorated with this test method attribute. Now let's write our first unit test to test that is even function. To do that, we're going to use asserts. We'll declare a test variable and then use the assert statement to test our test variable. So I'm gonna write our first test variable called test one and give it a integer value. So now we have a test variable and it's assigned a value of two. Now I will use the assert statement and call the is even function to test the function. So now I've written the assert statement and I am calling that is even function. I need to include the name space, that's why there's an error. And what this will do is say assert that this statement inside of the parenthesis is true. And inside of here, we are calling or is even function, that's the function we are testing. So now the unit test is completely written and we are ready to run it, to run your unit tests move to the Solution Explorer, right click on your unit test project and select run tests. What this will do is open the Test Explorer and start running your unit tests. You see a tree view here organized by projects, name space, the class and then we can see our individual unit tests. And all these green check marks mean that the unit test has passed and here in the right hand pane we can see some information about that specific unit test. We can see the source and how long that unit test took to run. Let's go add another unit test so we can see what a failed unit test looks like. So I'm gonna add a new test method here and purposely make it fail. So now I've added a second unit test called is even test two and I've set the variable to three. And that will cause this statement to fail because three is definitely not even. And we're asserting that a statement will be true. So I'm gonna come over to our Test Explorer tab and I'm gonna select the run all tests in view. This will run all of our unit tests again and we can see one of them fail. So here our tests have run and we can see is even test two has failed and we see an error message. So that is the basic framework for writing unit tests and testing them using the test runner. So now you know how to add a unit test project to your solution, write unit tests, and use the Test Explorer to run your unit tests. Stay tuned for the next lesson where we will cover using the MS Test framework to set up your unit test projects.