Mocking in .NET Core Unit Tests with Moq: Getting Started
Moq is the most popular mocking framework for .NET. This course will teach you how to isolate parts of your codebase for easier testing by creating and configuring test-time-only mock versions of dependencies.
What you'll learn
Writing unit tests can be difficult, time-consuming, and slow when you can't isolate the classes you want to test from the rest of the system. In this course, Mocking in .NET Core Unit Tests with Moq: Getting Started, you'll learn how to create mocks and use them as dependencies to the classes you want to test. First, you'll discover how to configure mocked methods and properties to return specific values. Next, you'll cover how to perform behavior/interaction testing. Finally, you'll explore how to setup mocked exceptions and events. When you're finished with this course, you'll have the necessary knowledge to use Moq to unit test your classes in isolation by creating and using mock objects.
Table of contents
- Introduction 2m
- Course Outline 1m
- An Overview of Mocking 1m
- Why Mock? 4m
- What Is a Unit? 2m
- Fakes, Dummies, Stubs, Mocks, and Test Doubles 4m
- An Overview of Moq 1m
- Demo Code Overview 2m
- Adding a Unit Test Project 2m
- Writing Initial Tests 3m
- Introducing a New Dependency and Installing Moq 5m
- Summary 1m
- Introduction 1m
- Instantiating and Using a Mock Object 4m
- Configuring Mock Object Method Return Values 4m
- Argument Matching in Mocked Methods 5m
- Understanding Strict and Loose Mocks 3m
- Strict Mock Example 2m
- Comparing Strict and Loose Mocks 2m
- Refactoring the Tests 2m
- Mocking Methods with out Parameters 3m
- Summary 1m
- Introduction 1m
- Behavior Testing and State-based Testing 3m
- Verifying a Method Was Called 3m
- Adding a Custom Error Message 1m
- Verifying a Method Was Not Called 2m
- Verifying a Method Was Called a Specific Number of Times 2m
- Verifying a Property Getter Was Called 1m
- Verifying a Property Setter Was Called 2m
- Summary 1m
- Introduction 1m
- Throwing Exceptions from Mock Objects 3m
- Raising Events from Mock Objects 4m
- Returning Different Results for Sequential Calls 2m
- Mocking Members of Concrete Types 3m
- Mocking Virtual Protected Members 3m
- Improving Mock Setup Readability with LINQ to Mocks 3m
- Refactoring the Test Class 2m
- Summary 2m