Master .NET and C# Unit Testing with NUnit and Moq
4.5 (21 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
218 students enrolled
Wishlisted Wishlist

Please confirm that you want to add Master .NET and C# Unit Testing with NUnit and Moq to your Wishlist.

Add to Wishlist

Master .NET and C# Unit Testing with NUnit and Moq

Become an expert in unit testing with NUnit, Moq, dotMemoryUnit, ReSharper and other tools!
4.5 (21 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
218 students enrolled
Created by Dmitri Nesteruk
Last updated 8/2017
English
Curiosity Sale
Current price: $10 Original price: $50 Discount: 80% off
30-Day Money-Back Guarantee
Includes:
  • 3 hours on-demand video
  • 1 Article
  • 1 Supplemental Resource
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
What Will I Learn?
  • What unit tests are for and how they are written
  • How to set up and use the NUnit test framework
  • What are the different test doubles: fakes, stubs, mocks
  • How to effectively use the Moq mocking framework
  • How to use the ReSharper unit test runner
  • How to write memory-related unit tests using dotMemoryUnit
View Curriculum
Requirements
  • Good understanding of C#
  • Familiarity with an IDE such as Visual Studio
Description

The goal of this course is to teach you Unit Testing and the use of the latest and greatest tools and frameworks available on the market today. This course covers the following technologies:

  • NUnit, the most popular unit test framework available for .NET
  • Moq, a mocking framework
  • dotMemoryUnit, a unit test framework for testing memory consumption
  • ReSharper (its unit test runner) used extensively in this course
  • dotCover is used to illustrate the concepts of code coverage and continuout testing

In this course you'll learn what unit tests are, how to write and execute them, what are fakes/mocks/stubs/moles and how to use a mocking framework.

Who is the target audience?
  • .NET developers wishing to learn about using unit testing
  • Experienced developers wishing to expand their unit testing skills
Students Who Viewed This Course Also Viewed
Curriculum For This Course
44 Lectures
03:13:36
+
Introduction
1 Lecture 03:32
+
Introduction to NUnit
6 Lectures 20:37

An overview of the things we're going to learn in this section of the course.

Introduction
00:57

What exactly is unit testing and why do we need it? Also, what is TDD?

What is Unit Testing?
02:59


Unit Test Runners: Standalone, VS, R#/Rider
07:11

Bank Account Scenario
04:28

A summary of the things we've learned in this section of the course.

Summary
01:04
+
Assertions
7 Lectures 28:30

An overview of the things we'll meet in this section of the course.

Overview
01:04

Basic Assertions and Possible Test Results
05:07

More information about ways of issuing warnings in unit tests.

Warnings
06:03

Arrange Act Assert
05:02


Exceptions
06:20

A summary of all the things we've learned in this section of the course.

Summary
01:18
+
Testing Methodologies
6 Lectures 29:19

An overview of different approaches to unit testing.

Overview
00:42

If you need to run a single unit test on several different sets of data, you can do so using the [TestCase] attribute. ReSharper, Rider and other tools support the running of test cases individually or collectively.

Preview 08:22

Code coverage tools give you information about the percentage of your code that is actually covered by your tests. Higher values are obviously better, but having 100% coverage is typically a goal not worth going for... unless you have a lot of time on your hands.

Code Coverage with dotCover
06:10

Continuous testing means that instead of running tests when you want them to run, you run them on every save or on every compile. Of course, the test runner needs to be smart enough to rerun only affected tests, not every single test that you have in your system.

Continuous Testing with dotCover
05:12

Control your app's memory consumption with JetBrains' free memory unit testing framework.

Memory Testing with dotMemoryUnit
07:54

A summary of all the things we've learned in this section of the course.

Summary
00:59
+
Test Doubles
8 Lectures 35:38

An overview of the lectures in this section of the course. Also, source code is attached here!

Overview
01:37

A discussion of why test doubles are required, and some of the varieties: mocks, stubs and fakes.

Mocks, Stubs, Fakes, Moles — What Are They All For?
05:54

A re-worked BankAccount scenario which gets a second component in as a dependency. Oh no, what do we do now?!

Scenario: Bank Account (again!)
04:13

Let's build a simple fake object. Nothing to it, really, provided you have an interface you can implement.

Static Fakes
02:44

A rather advanced approach to building fakes at runtime by defining a DynamicObject that can conform to any interface you might need.

Dynamic Fakes with ImpromptuInterface
09:20

Fakes are great, but if you depend on the behavior of a dependent object for correct operation, what then? We still need to fake it, but the results may need to be different depending on the tests. Stubs to the rescue!

Stubs
03:13

A more powerful incarnation of subs, mocks allow us to do many things, including testing the number of calls of a test double's method. Mocks are typically made through mock frameworks, but we'll roll a simple one ourselves.

Mocks
06:20

A summary of all the things we've learned in this module.

Summary
02:17
+
Mocking Test Objects with Moq
14 Lectures 01:14:44

An overview of this, rather large, section of the course that deals with Moq, a mocking framework.

Overview
00:56

We return to our scenario of a bank account depending on logging and see how we can solve this problem once and for all using the Moq library.

Get Started with Moq
05:21

We look at how to mock methods of an object, including an ability to specify particular return values dependent upon the input arguments.

Mocking Methods: Basics
04:37

You can direct mock methods to return values which are dependent upon the arguments passed into those methods.

Mocking Methods: Argument-Dependent Mocking
05:04

It's also possible to mock methods that have ref or out parameters, sometimes with surprising results.

Preview 09:10

We look at a few more sophisticated concepts of method mocking, including an ability to provide a functioning method body as well as what happens if you want to mock exception throwing.

Mocking Methods: Exceptions and Return Values
07:43

Having spent lots of time learning how to mock methods (their arguments and return values), we now turn to properties, which are much simpler.

Mocking Properties: Basics
08:13

A mock object's properties, by default, do not behave as properties: instead, they are no-op constructs. But what if you want them to behave like real properties, storing values and yielding them in setters? Well, Moq makes this possible (and easy).

Mocking Properties: Value Tracking
03:37

Having figured out methods and properties, we now turn to events: both those based on the typical sender-args arrangement as well as events constructed with custom delegates.

Mocking Events
09:36

Callbacks allow you to specify custom pieces of code to be invoked whenever some part of a mock object is being accessed. Useful for tracing and ad-hoc profiling.

Callbacks
05:33

Verification lets us check that a particular part of a mock object was, in fact, accessed a specific number of times.

Verification
04:57

Here we look at a few examples of customizing the behavior of mock objects.

Behavior Customization
06:07

If you decide to mock protected members, you need to use a slightly different interface. One unpleasant side effect is that, since those members are protected, you cannot feed their names via either Expression<T> or nameof. The end result is that, unfortunately, those have to be specified as strings, with all the associated performance implications.

Expectations for Protected Members
02:43

A summary of the myriad of things that we've learned in this section of the course.

Summary
01:07
+
End of Course
2 Lectures 01:20

A summary of all the things we've learned in this course.

Course Summary
01:03

About the Instructor
Dmitri Nesteruk
4.5 Average rating
1,055 Reviews
10,569 Students
14 Courses
Quant Finance • Algotrading • Software/Hardware Engineering

Dmitri Nesteruk is a developer, speaker and podcaster. His interests lie in software development and integration practices in the areas of computation, quantitative finance and algorithmic trading. His technological interests include C#, F# and C++ programming as well high-performance computing using technologies such as CUDA. He has been a C# MVP since 2009.

Dmitri is a graduate of University of Southampton (B.Sc. Computer Science) where he currently holds a position as a Visiting Researcher. He is also an instructor on an online intro-level Quantitative Finance course, and has also made online video courses on CUDA, MATLAB, D, the Boost libraries and other topics.