
This course includes our updated coding exercises so you can practice your skills as you learn.
See a demo
A small introduction of what you can expect from this course. What I will be explaining and what you can expect.
In this lecture, I will tell you what you should know and what I am using. This way you know if you can and want to follow this course.
So, what is unit testing? That is the question for this lecture. At the end of this lecture, you will have your answer.
Now we know what unit testing is I will answer the next question: Why?
Assertions are the biggest part of unit tests. But what are they and how do we use them?
There are two most used frameworks for unit testing C#: NUnit and XUnit. In this lecture I am going to explain the differences between them.
Time to write some code. In this lecture, I am explaining my starting point, create a basic unit test, and explain how you can run and check the results of your tests.
Creating code usually starts with a blank file, then it's full of code. This also happens with unit testing. So let's clean up a bit after the previous demonstration.
If a method throws an exception you should test if this exception is thrown and if it gives the correct information. Exceptions are a bit different if you want to test them. Let's take a look at how we can test them.
In some cases, your class or method needs external information. From a database for example. With unit testing, you don't want to access external sources like a database or API. And that's where mocking comes to help us. This is really important, maybe the most important part of this course.
Let's recap on what we have learned and how to continue from here.
While coding is fun and all, you need to make sure your code is always working. When something goes wrong customers usually blame the developers, but 7 out of 10 times it’s a wrong input but the customer. 2 out of 10 times it’s a logic problem (“well, didn’t see that one coming”), and 1 out 10 times its a developers error.
We, developers, cannot think for a customer or all the things a user can do. But we can make sure our code works as it should. Therefore, we should test our code. Not the application, but the logic that makes the application work. This is what we call ‘unit testing’.
In this course, I will explain and show you the basics of C# unit testing. I will start with the basic theory of unit testing and the difference between NUnit and XUnit, the two most test frameworks for C# and .NET. Other subjects are assertions, exception testing, and mocking are really important to know and explained. With some practical examples, I will show you how to use and implement them.
For this course, it is convenient if you have some experience with C# and .NET. You don't need any knowledge of unit testing, because that's what this course is all about.