4.3 out of 5
4.3
265 reviews on Udemy

Learn Unit Testing with NUnit and C#

Learn unit testing, TDD, mocking and Dependency Injection: techniques that you'll need to build reliable software.
Instructor:
Engineer Spock
1,687 students enrolled
English [Auto-generated]
Write Unit Tests
Run and Debug Unit Tests
Write Manual Mocks
Write Mocks with Mocking Framework
Practice Test-Driven Development (TDD)
Apply Best Practices of Writing Unit Tests

Learn deeply the concepts and tools that you will need to build maintainable and reliable software.

Teaching Approach

No fluff, no ranting, no beating the air. I esteem your time. The course material is succinct, yet comprehensive. All important concepts are covered. Particularly important topics are covered in-depth. For absolute beginners, I offer my help on Skype absolutely free, if requested. 

Take this course, and you will be satisfied.   

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 features   

  • Test Doubles including fakes, dummies, stubs, spies and mocks   

  • How to write manual test doubles and how to use a mocking framework  (NSubstitute)

  • TDD, red-green-refactor triplet   

  • A great number of best practices of writing unit tests   

  • Introduction to Dependency Injection

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 7.5 hours. All are video lectures. You will be able to download all the slides and code samples used in the course.         

————————————————————

Keywords related to the course:

  • Visual Studio unit testing tutorial

  • NUnit unit testing tutorial

  • Dot Net testing framework

  • C# unit test framework

  • Visual Studio unit testing framework tutorial

  • csharp unit testing tutorial   

  • TDD in C#

  • NSubstitute

  • TDD

  • Test Driven Development

  • unit testing C#

Getting Started

1
How to Ask Questions
2
Download Source Code and Slides
3
English Subtitles
4
Outline

The outline of the first section on the essentials of Unit Testing in .NET.

5
What is a Unit Test?

Learn what is a unit test in essence.

6
Unit-Testing Frameworks

Learn what is a unit testing framework, which frameworks exist and is it so important to stick with a specific one?

7
Your First Unit Test

Write your first unit test in Visual Studio in C# and NUnit unit testing framework.

8
Naming Conventions

Learn what naming conventions regarding unit test classes, unit tests and unit testing projects exist.

9
Running and Debugging Unit Tests

Learn how to run and debug unit tests in Visual Studio.

10
Benefits of Unit Testing

Learn what benefits do unit tests provide.

11
Who Should Write Unit Tests and When

In this lecture, we will answer the question about who should write unit tests? Programmers or maybe testers?

12
Programmer's Oath

Learn the Oath of Programmers.

13
Exercise: Degree Converter
14
Solution: Degree Converter
15
Conclusion

The conclusion of the first section on essentials of unit testing.

NUnit Framework

1
Outline

The outline of the second section on basics on NUnit unit testing framework.

2
Assert Introduction

Learn the basics of Assertions in unit tests.

3
Assert Demo

Learn how to write assertions with NUnit on practice.

4
Arrange-Act-Assert

Learn the Arrange-Act-Assert triplet.

5
Running Tests from the Console

Learn how to run unit tests from the Console.

6
SetUp and TearDown

Learn how to use special attributes of NUnit: SetUp and TearDown.

7
OneTimeSetUp and OneTimeTearDown

Learn how to use special attributes of NUnit: OneTimeSetUp and OneTimeTearDown.

8
Parameterized Unit Tests

Learn how to write parameterized unit tests with NUnit.

9
Grouping and Ignoring Unit Tests

Learn how to group and ignore unit tests with NUnit.

10
Code Coverage

Learn what is Code Coverage in unit testing.

11
Exercise: FizzBuzz
12
Solution: FizzBuzz
13
Exercise: Roman Numerals
14
Solution: Roman Numerals
15
Exercise: Stack
16
Solution: Stack
17
Conclusion

The conclusion of the second section on the essentials of the NUnit unit testing framework.

Test Doubles

1
Test Doubles and Dependency Injection
2
Outline

The outline of the third section on essentials of test doubles in unit testing.

3
Demo of a Testing Problem

Demonstration of a case when it's hard to unit test the logic.

4
Refactoring to Make Code Testable

Demo of how to refactor bad code to make it testable.

5
Test Doubles

Learn the different types of test doubles such as mock, stub, spy, fake, dummy,

6
Hand Rolled or Manual Test Doubles

Learn how to write test doubles manually, without using any mocking framework.

7
Problems with Manual Test Doubles

Learn the problems related to writing manual test doubles.

8
Mocking Frameworks

Learn what is a mocking framework, which exist and which one to pick.

9
Writing Unit Tests with a Mocking Framework

Learn how to write a unit test with test doubles powered by a mocking framework.

10
NSubstitute Mocking Framework. Key Features. Demo

Learn the main features of NSubstitute mocking framework.

11
Detroit School vs London School of Unit Testing

Learn the difference between Detroit School and London School of Unit Testing.

12
Conclusion

The conclusion of the third section on the essentials of mocking frameworks.

Test-Driven Development

1
Outline

The outline of the fourth section on essentials of Test-Driven Development.

2
What is TDD?

Learn what is TDD.

3
Red Green Refactor

Learn RedGreenRefactoring process of TDD.

4
TDD and Design Upfront

Learn what is the difference between Design Upfront and TDD.

5
Regular Agile Process in 200 Words
6
VS and R# Shortcuts
7
Refactoring Commands Built-In VS 2017
8
Fibonacci Numbers
9
Three Main TDD Techniques
10
Grabbing the Gold
11
FizzBuzz
12
Reading Roman Numerals
13
UpdateableSpin
14
Continuous Testing
15
Tic-Tac-Toe (Crosses and Noughts)
16
Assert First
17
TDD Demo - Game in Sticks

The demonstration of TDD on the example of programming a simple console game.

18
Conclusion

Best Practices of Unit Testing

1
Outline

Outline of the fifth section on best practices of unit testing.

2
Do Unit Tests Guarantee the Success?

In this lecture we will answer the question "Do Unit Tests Guarantee the Success?"

3
Pragmatic Unit Testing

Learn what is pragmatic unit testing.

4
Integration Tests

Learn what are integration tests.

5
Singletons and Static Classes

Learn what is a singleton design pattern and how it damages the ability to write unit tests.

6
Header Interfaces

Learn about the smell of header interfaces. They very often appear when we introduce them just for the sake of writing mocks.

7
Demo of Refactoring to a Testable Design

Demo of a refactoring of untestable code to the state when it is testable (when we can write unit tests).

8
How Much Test Coverage is Enough?

Learn how much test coverage is enough.

9
Testing Trivial Code

Do we need to write unit tests for trivial code?

10
The Rule of Testing a Single Concern

Learn what really means the rule of a Single Concern in a single unit test.

11
More on Best Practices

Learn more about general best practices of writing unit tests.

12
Generating Unit Test Method Signatures

Learn how to easily generate signatures of unit test methods.

13
Conclusion

Conclusion of the fifth section on the best practices of writing unit tests.

14
Final Quiz
15
BONUS LECTURE

Appendix. Intro to Dependency Injection

1
Outline
2
Definition of DIP
3
Dependencies
4
Volatile and Stable Dependencies
5
Definition of IoC and DI
6
DIP Violation Demo
7
Refactoring to a Better Design
8
Dependency Injection Techniques
9
Architectural Implications
10
Common Smells of DIP Violation
11
Conclusion

Appendix. Intro to DI. IoC-Containers

1
Outline
2
Pure DI and IoC-Containers
3
Building a Simple IoC-Container
4
Service Locator
5
Demo with an IoC-Container
You can view and review the lecture materials indefinitely, like an on-demand channel.
Definitely! If you have an internet connection, courses on Udemy are available on any device at any time. If you don't have an internet connection, some instructors also let their students download course lectures. That's up to the instructor though, so make sure you get on their good side!
4.3
4.3 out of 5
265 Ratings

Detailed Rating

Stars 5
107
Stars 4
115
Stars 3
36
Stars 2
2
Stars 1
5
302fed75b09c935bca6afd68f695fe52
30-Day Money-Back Guarantee

Includes

8 hours on-demand video
5 articles
Full lifetime access
Access on mobile and TV
Certificate of Completion