Video: Unit Testing With C#

Learn Unit Testing With C#

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 with C#.

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 it’s a developers error.

In this tutorial, I will explain and show you the basics of unit testing with C#. I will start with the basic theory of unit testing and the difference between NUnit and XUnit, the two most common test frameworks for C# and .NET. Other subjects are assertions, exception testing, and mocking are really important to know and explain. With some practical examples, I will show you how to use and implement the unit testing with C#.

Find this course at:

What you will learn

  • The idea behind unit testing with C#
  • Create a basic unit test with assertions
  • Learn the differences between Fact and Theory
  • How to unit test methods with exceptions
  • Mocking interface to remove dependencies in unit testing

Win free lessons by signing up for the newsletter.

By subscribing to the newsletter, you have a chance to win a free lesson. If you win, you will receive an email with instructions and a link to follow the lesson.

Course overview

See what you will learn in unit testing with C#

1

Introduction

A small introduction of what to expect and what not to expect for this course.

2

Requirements

There are a few requirements if you want to take this course. In this lecture, I explain what these are so you know what to expect.

3

Why Unit Testing

Let’s first look at why we are using unit testing with C#.

4

What Is Unit Testing With C#

Now we know the why, let’s look at what unit test is and what what the idea behind it is.

5

Assertions

Unit tests use assertions. Time to dive into assertions.

6

NUnit vs XUnit

There are two frameworks you can use for unit testing with C#: NUnit and XUnit. But what are the differences and when do you use NUnit and when do you use XUnit?

7

Basic Unit Test

Now that we have covered the theory, it’s time to create a real unit test. We keep it basic for now.

8

Exceptions

Exceptions will happen in your application. Some are thrown by you and some happen because of bad input or data. In this chapter, we look at how we can unit test those exceptions.

9

Conclusion Unit Testing With C#

Let’s wrap it up. A small recap of the previous chapters and some pros and cons.

Kens Learning Curve