Mocking with Moq 4 and xUnit
Writing unit tests is hard when dependencies between classes make it tough to separate what's being tested from the rest of the system. Moq, the most popular mocking library for .NET, makes it easy to create mock dependencies to make testing easier.
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 with Moq 4 and xUnit, 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 learn how to perform behavior/interaction testing to check your classes are interacting correctly with their dependencies. Finally, you'll explore how to setup mock exceptions, mock events, and use additional mocking techniques. 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 1m
- Installing Moq 2m
- Instantiating and Using a Mock Object 4m
- Configuring Mock Object Method Return Values 4m
- Argument Matching in Mocked Methods 6m
- Understanding Strict and Loose Mocks 2m
- Strict Mock Example 3m
- Comparing Strict and Loose Mocks 1m
- Refactoring the Tests 2m
- Mocking Methods with Out Parameters 3m
- Matching ref Arguments with Moq 4m
- Summary 1m
- Introduction 1m
- Behavior Testing and State Based Testing 4m
- Verifying a Method Was Called 4m
- Adding a Custom Error Message 1m
- Verifying a Method Was Not Called 3m
- Verifying a Method Was Called a Specific Number of Times 2m
- Verifying a Property Getter Was Called 3m
- Verifying a Property Setter Was Called 4m
- Summary 1m
- Introduction 1m
- Throwing Exceptions from Mock Objects 4m
- Raising Events from Mock Objects 4m
- Returning Different Results for Sequential Calls 2m
- Checking a Mock Method Was Called Multiple Times with Different Values 3m
- Mocking Members of Concrete Types with Partial Mocks 3m
- Mocking Virtual Protected Members 4m
- Improving Mock Setup Readability with LINQ to Mocks 2m
- Refactoring the Test Class 3m
- Matching Generic Type Arguments 3m
- Mocking Async Method Return Values 1m
- Summary 2m