Learn Unit Testing with NUnit and C#

Learn Unit Testing with NUnit and C#

Learn the basics of unit testing and related concepts like mocking that you'll need to build reliable software.

What You'll Learn

Write Unit Tests
Write Manual Mocks
Practice TDD
Best Practices of Unit Testing
Run and Debug Unit Tests
Learn Mocking Framework

About

Build a solid foundation in Unit Testing with this course 

This course is all about writing effective unit tests using C# programming language and NUnit as a unit testing framework. Along the way, we will learn the concepts related to unit testing. Today unit testing is an absolutely required skill from any professional developer. Companies expect from developers to know how to write unit tests including all the most important topics such as mocking and test driven development (TDD in short). This course does not cover all the features of NUnit. This course is way more interesting.

Learning unit testing puts a powerful and very useful tool at your fingertips. Being familiar with unit testing you can write reliable and maintainable applications. It is very hard to lead a project which is not covered by unit tests. 

Content and Overview

This course is primarily aimed at beginner developers. It provides solid theoretical base reinforced by tons of practical material.

We start with basics of unit testing. What is a unit test? What unit testing frameworks exist? How to run and debug unit tests. After getting acquainted with the basics, we will get to the NUnit framework. Here you’ll learn how to install the framework, set the runner. Then you’ll learn the basics of assertions and arrange-act-assert triplet. Other key features of NUnit are also covered:

  • Running tests from the console 
  • Setup and teardown unit tests 
  • Parameterized tests 
  • Grouping and ignoring 

Practicing writing of unit tests, it’s impossible to avoid applying mocks. I like the word “test double” more, in general. By the way, you’ll learn what the difference between the following notion is:

  • Test double 
  • Fake 
  • Dummy 
  • Stub 
  • Mock 

You’ll learn how to write test doubles manually. You will also see a simple example of how to use a mocking framework for using mocks. I’ll use NSubstitute mocking framework for demonstration.

At the end of this section, you’ll get acquainted with two key approaches to unit testing, Classic or Detroit School and London School of unit testing. 

You’ll separately learn the basic of test-driven development. It is hard to imagine a modern professional developer who doesn’t know about TDD, so you’ll learn what it is and what it is about. You’ll see the Red-Green-Refactor triplet in action.

I could not complete the course avoiding the best practices of writing unit tests. You’ll learn the basic concepts of the modern approach to unit testing called “pragmatic unit testing”. You’ll see what problems static classes and singletons bring regarding the unit testing. They make code harder to unit test. After that, you’ll learn the problem of extracting interfaces just for the sake of introducing shims for injecting dependencies. 

You’ll know should you write unit tests for the trivial code. You’ll learn a lot more in the course.

So, in short, the course covers the following topics:

  • Basic notions of Unit Testing 
  • NUnit and its basic features 
  • Test Doubles including fakes, dummies, stubs, spies, and mocks 
  • How to write manual test doubles and how to use a mocking framework 
  • TDD, red-green-refactor triplet 
  • A great number of best practices of writing unit tests 

In the end, we will recap what you have learned, and you will try to understand where you have to go further with the intention to master your skills.

How long is this course: The course is around 4 hours. All are video lectures. You will be able to download all the slides and code samples used in the course. 

54

Lessons

5

Modules

1

Quizzes

0

Reviews

Try for 30 days

Try Now

30 day money back guarantee

Modules

Getting Started
How to Ask Questions
Download Source Code and Slides
0:58 Outline
3:11 What is a Unit Test?
3:25 Unit-Testing Frameworks
8:43 Your First Unit Test
4:34 Naming Conventions
5:20 Running and Debugging Unit Tests
3:35 Benefits of Unit Testing
2:51 Who Should Write Unit Tests and When
3:29 Programmer's Oath
1:15 Conclusion
NUnit Framework
1:60 Outline
5:30 Assert Introduction
10:27 Assert Demo
1:10 Arrange-Act-Assert
1:51 Running Tests from the Console
4:51 SetUp and TearDown
2:14 OneTimeSetUp and OneTimeTearDown
3:12 Prameterized Unit Tests
2:14 Grouping and Ignoring Unit Tests
1:42 Code Coverage
1:38 Conclusion
Test Doubles
1:90 Outline
3:44 Demo of a Testing Problem
4:20 Refactoring to Make Code Testable
5:56 Test Doubles
11:54 Hand Rolled or Manual Test Doubles
1:17 Problems with Manual Test Doubles
7:46 Mocking Frameworks
7:46 Writing Unit Tests with a Mocking Framework
18:70 NSubstitute Mocking Framework. Key Features. Demo
2:23 Detroit School vs London School of Unit Testing
1:18 Conclusion
Test-Driven Development
0:41 Outline
5:00 What is TDD?
4:16 Red \ Green \ Refactor
2:36 TDD and Design Upfront
40:22 TDD Demo
0:34 Conclusion
Best Practices of Unit Testing
0:55 Outline
2:26 Do Unit Tests Guarantee the Success?
5:16 Pragmatic Unit Testing
4:18 Integration Tests
7:30 Singletons and Static Classes
5:56 Header Interfaces
14:29 Demo of Refactoring to a Testable Design
2:37 How Much Test Coverage is Enough?
2:59 Testing Trivial Code
3:60 The Rule of Testing a Single Concern
10:19 More on Best Practices
1:26 Generating Unit Test Method Signatures
2:32 Conclusion
Final Quiz

How It Works

Coursework

Coursework

Each course is like an interactive textbook with pre-recorded videos, quizzes and projects.
Peer Support

Peers

Connect with thousands of other learners to debate ideas, discuss course material, and get help mastering new concepts.

Your Teacher